ryanfc Posted August 29, 2007 Share Posted August 29, 2007 Ok I got this tutorial on writing to a database out of a book I have: PHP for the World Wide Web. However, it is not working. Can anyone help me with what I am doing wrong? Here is the code for the page. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>myevvspace.com | premium local listings</title> <link href="myevvspace_style_home.css" rel="stylesheet" type="text/css" /> <script src="navigation.js" type="text/javascript" language="javascript"></script> <?php require('taken out for security'); ?> </head> <body> <?php if (isset ($_POST['submit'])) { if ($dbc = mysql_connect ($dbhost, $dbuser, $dbpass)) { if (!mysql_select_db ('contactform')) { die ('could not select' . mysql_error() . ' '); } } else { die ('coud not connect' . mysql_error() . ' '); } $query = "INSERT INTO contactform (contact_id, name, email) VALUES (0, '{$_POST['name']}', '{$_POST['email']}')"; if (mysql_query ($query)) { print 'added'; } else { print "not added" . mysql_error() . "the query was $query"; } mysql_close(); } ?> <form method="POST" action="contact.php"> <p> <input name="name" type="text" /> </p> <p> <input name="email" type="text" /> </p> <p> </p> <p> <input type="submit" name="Submit" value="Submit" /> </p> </form> </body> </html> Thanks. Quote Link to comment Share on other sites More sharing options...
mcmuney Posted August 29, 2007 Share Posted August 29, 2007 I think you need to be more specific. Did you create the database with the table? Did you have all the files? What errors are you getting? Quote Link to comment Share on other sites More sharing options...
ryanfc Posted August 29, 2007 Author Share Posted August 29, 2007 i have a database created and a table in that database called contactform. that table has 3 fields contact_id (the key), name and email. When a user goes to the contact.php page i want them to fill out the form and when it they hit submit I want it to send the name and e-mail to the contactform table. I eventually want the page to have more fields and have it write just the name and email address to the database and send all fields in an e-mail. But first I am just trying to get it to write to the database. Does that make sense? Quote Link to comment Share on other sites More sharing options...
mcmuney Posted August 29, 2007 Share Posted August 29, 2007 Makes sense, so what error are you getting? Quote Link to comment Share on other sites More sharing options...
ryanfc Posted August 29, 2007 Author Share Posted August 29, 2007 well that is the thing...it does not give me any error and I check the database and nothing is there. here is the page: http://myevvspace.com/contact.php Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 29, 2007 Share Posted August 29, 2007 Add error reporting to the top of your pages: ini_set('display_errors', 1); error_reporting(E_ALL); Do you see any errors now? Quote Link to comment Share on other sites More sharing options...
ryanfc Posted August 29, 2007 Author Share Posted August 29, 2007 No I do not. I added those lines and have changed a few things so here is the new code for the page. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>myevvspace.com | premium local listings</title> <link href="myevvspace_style_home.css" rel="stylesheet" type="text/css" /> <script src="navigation.js" type="text/javascript" language="javascript"></script> <?php require('///////'); ?> </head> <body> <?php ini_set('display_errors', 1); error_reporting(E_ALL); if (isset ($_POST['submit'])) { if ($dbc = mysql_connect ($dbhost, $dbuser, $dbpass)) { if (!mysql_select_db ($dbname)) { die ('could not select' . mysql_error() . ' '); } } else { die ('coud not connect' . mysql_error() . ' '); } $query = "INSERT INTO contactform (contact_id, name, email) VALUES (0, '{$_POST['name']}', '{$_POST['email']}')"; if (mysql_query ($query)) { print 'added'; } else { print "not added" . mysql_error() . "the query was $query"; } mysql_close(); } ?> <form method="POST" action=""> <p> <input name="name" type="text" /> </p> <p> <input name="email" type="text" /> </p> <p> </p> <p> <input type="submit" name="Submit" value="Submit" /> </p> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 29, 2007 Share Posted August 29, 2007 Well $_POST['submit'] is never set. You have it as "Submit" not 'submit' Quote Link to comment Share on other sites More sharing options...
ryanfc Posted August 29, 2007 Author Share Posted August 29, 2007 well that was simple. thanks! Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 29, 2007 Share Posted August 29, 2007 Error reporting should have caught that :/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.