LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-01-2004, 12:33 AM   #1
sinsoush
LQ Newbie
 
Registered: Mar 2004
Posts: 3

Rep: Reputation: 0
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
 
Old 04-01-2004, 03:46 AM   #2
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 50
the code you have listed above doesnt do anything when submit is pressed.
 
Old 04-01-2004, 06:25 AM   #3
sinsoush
LQ Newbie
 
Registered: Mar 2004
Posts: 3

Original Poster
Rep: Reputation: 0
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
 
Old 04-01-2004, 04:57 PM   #4
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 50
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))
 
Old 04-01-2004, 08:02 PM   #5
Meditator
LQ Newbie
 
Registered: Mar 2004
Posts: 4

Rep: Reputation: 0
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"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP: html Form Select function problem camlinux Programming 2 05-15-2005 08:23 PM
Simple PHP help with a form :-) 2782d4 Programming 3 12-17-2004 02:53 AM
PHP:Unable to post variables from html form to mysql database vikram_cvk Linux - Software 1 09-29-2004 03:01 PM
PHP and HTML Form Post Savahn Programming 12 06-30-2004 03:15 PM
Simple PHP form not working... Booster Programming 4 02-23-2004 02:50 PM


All times are GMT -5. The time now is 11:34 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration