Simple php script with html form not working.
Greetings,
I am really stuck on this problem, so I hope someone can give me a hand: I just installed Red Hat 9 for the third time. I installed PHP 4.3.5, MYSQL 4.0.18, and APACHE 2.0.49 via the following tutorial. //madpenguin.org/article751.html I can create a php file that queries my MySQL database and return the results no problem. I can also create a simple php file that contains <?php phpinfo(); ?> and it returns all of my PHP Version 4.3.5 info. If seeing the phpinfo() results is needed, please let me know. My problem is as soon as I create a php file with the below code, I get nothing. When I fill out the fields and hit submit, the fields clear and nothing else happens? <html> <body> <form method="post" action="<?php echo $PHP_SELF?>"> First name:<input type="Text" name="first"><br> Last name:<input type="Text" name="last"><br> Address:<input type="Text" name="address"><br> Position:<input type="Text" name="position"><br> <input type="Submit" name="submit" value="Enter information"> </form> </body> </html> I have been looking all over in different forums for information on this problem. I am a newbie to Linux, so I am kind of doing a trial and error. The only changes I have made to MySQL, PHP, or APACHE files are the ones listed at //madpenguin.org/article751.html The only exception is I changed register_globals = ON. Please let me know if i can provide any additional information to assist in the solution. Thank you for any help you can provide, I am at a loss what is wrong?? Cheers, Travis |
the code you have listed above doesnt do anything when submit is pressed.
|
First of all, thank you kev82 for taking the time to look over my issue.
I apologize, but the snippett of code I pasted for you to examime was not the correct one. It was going on 2am when I posted, I will try to take my time in the future. Below is the code I needed examined: <html> <body> <?php if ($submit) { // process form while (list($name, $value) = each($HTTP_POST_VARS)) { echo "$name = $value<br>\n"; } } else{ // display form ?> <form method="post" action="<?php echo $PHP_SELF?>"> First name:<input type="Text" name="first"><br> Last name:<input type="Text" name="last"><br> Address:<input type="Text" name="address"><br> Position:<input type="Text" name="position"><br> <input type="Submit" name="submit" value="Enter information"> </form> <?php } // end if ?> </body> </html> The above does nothing but clear the form fields, and that is it? In addition, if i run the code below, a blank entry is made in the mydb database. <html> <body> <?php if ($submit) { // process form $db = mysql_connect("localhost", "root"); mysql_select_db("mydb",$db); $sql = "INSERT INTO employees (first,last,address,position) VALUES ('$first','$last','$address','$position')"; $result = mysql_query($sql); echo "Thank you! Information entered.\n"; } else{ // display form ?> <form method="post" action="<?php echo $PHP_SELF?>"> First name:<input type="Text" name="first"><br> Last name:<input type="Text" name="last"><br> Address:<input type="Text" name="address"><br> Position:<input type="Text" name="position"><br> <input type="Submit" name="submit" value="Enter information"> </form> <?php } // end if ?> </body> </html> Thank you again to anyone that can help. Travis |
my php's not too great but the problem is obviously that "if($submit)" isnt working, at a guess i would say when you click the button your browser sets the submit variable but sets it to something that evaluates to false, try instead if(isset($submit))
|
you should use $_POST["submit"] instead of $submit, if the method is "get" then use $_GET["submit"], it is the way to access data since PHP 4.1.0
see "//cn.php.net/manual/en/language.variables.external.php" |
All times are GMT -5. The time now is 09:04 AM. |