PDA

View Full Version : Help with this PHP Script Please



KingPhil
23rd September 2006, 05:21 AM
I have scripted this simple PHP page right out of a book and it doesn't work. You are meant to enter a number and it will state whether the number you entered is a positive number, negative number or 0. When I use it, nothing happens. You can view it here: http://www.philip.family.nu/form2.php.

Here is the source code:



<html>
<head></head>
<body>

<?php

if (!$_POST['submit'])
{
?>

<form action="<?=$_SERVER['PHP_SELF']?>" <method="post">
Enter a number: <input name="number" size="2">
<input type="submit" name="submit" value="Go">
</form>

<?php
}
else
{

$number = $_POST['number'];
if ($number > 0)
{
echo 'You entered a positive number';

}
elseif ($number < 0)
{
echo 'You entered a negative number';
}
else
{
echo 'You entered 0';
}
}
?>

</body>
</html>

Carnage
23rd September 2006, 07:25 AM
<form action="<?=$_SERVER['PHP_SELF']?>" <method="post"> chnage that to

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">

KingPhil
24th September 2006, 01:53 AM
Thanks, Carnage, that is another example that even the simplest mistakes using PHP can make the biggest differences.

Carnage
24th September 2006, 07:21 AM
that was a html error. php errors are usually friendly and tell you something is wrong; even thou quite a lot of the time, the error isn't the problem but a result of a different error on the line above.

KingPhil
24th September 2006, 07:33 AM
You are right, that is true, I should have been less specific in my previous post and said "coding" or something else, but anyway, thanks again.

steviebutt2002
9th January 2007, 01:38 PM
that and remove <html>
<head></head>
<body>
code they tamper with php

Carnage
9th January 2007, 02:36 PM
that and remove <html>
<head></head>
<body>
code they tamper with php

no, they dont.

only time you need to worry about them is if you are modifying headers...

Ginsley
9th January 2007, 03:00 PM
:| but with game steve is codin it screwed it up big time till he removed the html tags and body tags and such
unless it depends on the code i guess it doesnt effect

Carnage
9th January 2007, 07:20 PM
probably cause he was trying to set cookies.