HTML Forms

A

Anonymous

Guest
I am new to PHP, I am using it with mysql and am trying to get a basic database to work but cannot get past this one little thing. I am using a form to transfer user input from an input page, over to a page that puts the information into the database. The problem is that the info is not getting over to the second page. I have my form "post" the information and when the other page opens up the information is somehow lost or invisible to my php.
Here is what I have (basically) in my input.php page
Code:
<form action=insert_info.php method=post>
<input type=text size=40 name=name>
<input type=submit name=submit value=submit>
</form>

And in my insert_info.php page I have
Code:
<?php
if ($submit== "submit")
{
$query = "insert into usertable
(name) values
('name')"
;
mysql_query($query) or
die (mysql_error());
?>

My info is not getting through, and I have found through the troubleshooting process that the values for $submit and $name are null. I also tried putting them through "get" rather than "post" and the info shows up in my address bar, but is not available to my php. Do I need to use a function to get these variables like http_get_vars or something? I am lost, and have little form history. Any help would be appreciated and thank you ahead of time.[/code]
 
*sigh* I wish someone would clean up all of the old tutorials that're misleading all of the newbies. The short answer, determined, is that now register_globals (Google it if you really want to know) is turned off by default, so you have to access your form variables via the $_GET or $_POST (or $_REQUEST) arrays. So, if your form method is GET, use $_GET['varname'], where varname is the name of your form field.

By the way, concerning your HTML, you need to put quotation marks around all of your attributes or it won't validate:

Code:
<form action=insert_info.php method=post>
<input type=text size=40 name=name>
<input type=submit name=submit value=submit>
</form>



<form action="insert_info.php" method="POST">
<input type="text" size="40" name="name">
<input type="submit" name="submit" value="submit">
</form>

Your new rule of thumb is this: Just because it works doesn't mean it's correct.
 
Thank you for your informative answer, I took a trip to my local bookstore and found the same answer after looking at many php books.

Thanks again for your prompt explaination to my problem. I by the way was reffering to a PHP/MYSQL book in my venture to learn PHP. Unfortunately the book I chose was a little out of date, and has not been updated since I purchased it. I have found a new set of authors that I am happy with, and who also update their material periodically.
 
Back
Top