PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hey guys, below is my software spec...
Win XP Pro
IE7
PHP5
Apache 2
I am running all files locally on the machine, they are not hosted anywhere...
As I said, I am completely new to html, php, mysql, and am learning from a simple book, my problem is this...
I have a simple html form that the user can insert their name and select a few options. When they click the submit button, the information is supposed to be passed to a PHP file that displays a little welcome message which includes their name and the options from the previous page. But the information is not getting passed for some reason.
Do I need to enable something on my IE7 to allow data to get passed at all. Below is the code
HTML file...
[syntax="html"]<html><head><title> Your Favourites </title></head>
<body>
<form action="fav.php" method="post">
<b> Please enter your name: </b> <br>
<input type="text" size="45" name="username"> <br><br>
<b> Please select your favourite wine </b><br>
<input type="radio" name="colour" Value="White"> White
<input type="radio" name="colour" Value="Rosé"> Rosé
<input type="radio" name="colour" Value="Red"> Red <br><br>
<b> Please enter your favourite dish </b><br>
<input type="text" size="45" name="dish"> <br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Change $username, $colour and $dish to $_POST['username'], $_POST['colour'] and $_POST['dish'].
Your book assumes superglobals are on, which is often considered bad practice. When accepting and dealing with variables passed from a HTML form, and the form method attribute is set to post, always reference the variables how I have demonstrated.
If the book you are using is teaching you to rely on register_globals being on, burn the book and go get a real book.
You should always fetch your form data through the $_POST super global array and then check it, validate it and report errors to your users so they can't screw with your app.
Hey guys, thanks for this information. I have changed what you said but I get an error message in explorer now which I cant understand. I have checked the php code over and over but cant find anything...
<html><head><title> Your Submission </title></head>
<body>
<?
if($_POST['username'] !=null)
{
echo("Thanks for your selection $_POST['username']<hr>");
}
if( ($_POST['colour'] !=null) && ($_POST['dish'] !=null) )
{
$msg="You really enjoy $_POST['dish']<br>";
$msg.="- especially with a nice $_POST['colour'] wine";
echo ($msg);
}
?>
</body>
</html>
The error message in IE is as follows...
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\xampp\htdocs\fav.php on line 9
you can turn register globals on or off via the php.ini file with the directive "register_globals=". Once you change anything in your php.ini file, you will need to restart you webserver.