HTML Forms

Discussing Html . Code , Software , other

Moderators: macek, egami, gesf

User avatar
determined
New php-forum User
New php-forum User
Posts: 23
Joined: Sun Sep 28, 2003 12:19 pm
Location: Table Arizona
Contact:

HTML Forms

Postby determined » Sun Sep 28, 2003 12:35 pm

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: Select all

<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: Select all

<?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]

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Postby swirlee » Sun Sep 28, 2003 10:20 pm

*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: Select all

<!-- This is wrong, and ugly: -->

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

<!-- This is correct: -->

<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.

User avatar
determined
New php-forum User
New php-forum User
Posts: 23
Joined: Sun Sep 28, 2003 12:19 pm
Location: Table Arizona
Contact:

thank you

Postby determined » Mon Sep 29, 2003 9:43 am

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.


Return to “HTML Basics”

Who is online

Users browsing this forum: No registered users and 2 guests

cron