silverglade Posted July 3, 2010 Share Posted July 3, 2010 my code wont work, any help appreciated. it is supposed to take the user first name, last name, and age and insert it into the database, then echo out. "thank god it worked". any help GREATLY!@ appreciated. thanks. derek here is the code to the page. <?php // i usually just add this, include('formconnect.php'); //but for learning sake ill type in this.. $username = 'root'; $password = ''; $host = 'localhost'; $database = 'form'; $connection = mysql_connect($host, $username, $password); if(!$connection){ die('could not connect: '. mysql_error()); } mysql_select_db($database, $connection); echo "<pre>".print_r($_POST, 1)."</pre>";//for debugging, whats inside POST if(isset($_POST['submit'])) { $sql="INSERT INTO userinfo (first, last, age) VALUES ('$_POST[first]','$_POST[last]','$_POST[$age]')"; echo $sql;//used to see whats in $sql. mysql_query($sql)or die(mysql_error());//for live// die("could not insert message"); echo "you successfully addded your info to the database thank god it worked.<br />"; echo "all your x and t's were crossed, and you had NO ERRORS YAY"; } mysql_close($connection) ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>derek's form</title> </head> <body> <form action="form.php" method ="post"/> Enter first name please:<input type="text" name="first"/><br /> Enter last name please<input type="text" name="last"/><br /> Enter your age please<input type=text" name="age"/> <input type="submit"/> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/206625-my-code-wont-insert-data-from-form-into-the-database/ Share on other sites More sharing options...
silverglade Posted July 3, 2010 Author Share Posted July 3, 2010 thank god it finally freaking worked. it sux being a total newbie. ok here is the full working code for all the other newbies out there. lol. derek <?php // i usually just add this, include('formconnect.php'); //but for learning sake ill type in this.. $username = 'root'; $password = ''; $host = 'localhost'; $database = 'form'; $connection = mysql_connect($host, $username, $password); if(!$connection){ die('could not connect: '. mysql_error()); } mysql_select_db($database, $connection); //echo "<pre>".print_r($_POST, 1)."</pre>";//for debugging, whats inside POST if(isset($_POST['submit'])) { $sql="INSERT INTO userinfo (first, last, age) VALUES ('$_POST[first]','$_POST[last]','$_POST[age]')"; //echo $sql;//used to see whats in $sql. mysql_query($sql)or die(mysql_error());//for live// die("could not insert message"); echo "you successfully addded your info to the database thank god it worked.<br />"; echo "all your x and t's were crossed, and you had NO ERRORS YAY"; } mysql_close($connection) ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>derek's form</title> </head> <body> <form action="form.php" method ="post"/> Enter first name please:<input type="text" name="first"/><br /> Enter last name please<input type="text" name="last"/><br /> Enter your age please<input type=text" name="age"/> <input type="submit" name="submit"/> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/206625-my-code-wont-insert-data-from-form-into-the-database/#findComment-1080659 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.