...

View Full Version : Need some help with Forms



tigerfang
10-17-2004, 08:06 PM
Hey everyone...
I'm just learning php and am using forms to load data into a database.... now, before you go saying that this is in the wrong topic, please read on.... My problem is that I have a form on one page, and a submit button. When the user submits the form, the page in the "action" property is loaded... however it seems like the data from the form isn't carried over. Can anyone help me?

Here is my form code:



<form method="post" action="create_entry.php">
<b>Name:</b><input type=text size=40 name=name><br>
<b>Location:</b><input type=text size=40 name=location><br>
<b>Email:</b><input type=text size=40 name=email><br>
<b>Home Page URL:</b><input type=text size=40 name=url><br>
<b>Comments:</b>
<textarea name=comments cols=40 rows=4 wrap=virtual></textarea>
<br>
<input type=submit name=submit value="Sign!">
<input type=reset name=reset value="Start Over">
</form>


and here is the php that handles the request on the next page...


<?php

include("dbconnect.php");

if($submit=="Sign!")
{
$query = "insert into guestbook
(name,location,email,url,comments) values
('$name','$location','$email','$url','$comments')"
;
mysql_query($query) or
die (mysql_error());

?>
<h2>Thanks!!</h2>
<h2><a href="view.php">View Guestbook</a></h2>

<?php
}
else
{
echo "Error<br>";

//include("sign.php");
}
?>


Thanks for any help...

Michael

Brandoe85
10-17-2004, 09:46 PM
Maybe this should be in the php forum, but anyways try changing your php code like this:


<?php

include("dbconnect.php");

if($_POST['submit']=="Sign!")
{
$query = "insert into guestbook values('".$_POST[name]."', '".$_POST[location]."', '".$_POST[email]."', '".$_POST[url]."', '".$_POST[comments]."')";
mysql_query($query) or
die (mysql_error());
?>
<h2>Thanks!!</h2>
<h2><a href="view.php">View Guestbook</a></h2>
<?php
}
else
{
echo "Error<br>";

//include("form.php");
}
?>

Hope this helps a little :thumbsup:

tigerfang
10-18-2004, 08:00 PM
Thanks,
It worked :)

bnovc
10-18-2004, 08:23 PM
You should have register globals off in the first place.

This means the use of $_GET (url) and $_POST (form) superglobals.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum