brokenshadows Posted April 22, 2009 Share Posted April 22, 2009 To start, let me say that I'm new to both MySQL and PHP. If fact, this is the first time I've tried to build anything from scratch with both. I've worked with databases before and have a good understanding of how they are supposed to work, but I obviously have no idea how to use PHP to connect to one. If my question has been answered in another post, please accept my apologies and direct me to said post. My problem is that I have a database that I'm trying to add data into using a simple form. When I fill in the form and hit my Submit button...nothing happens beyond the form fields clearing themselves. After hitting Submit, I pull up the database in phpMyadmin and there is no new data to be seen anywhere. Here's the code for the form page: <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>RMVD</title> </head> <body> <form id="contacts" name="contacts" method="post" action"contacts_insert.php"> <p>Parent's First Name: <input name="first" type="varchar" id="first" /> </p> <p>Parent's Last Name: <input name="last" type="varchar" id="last" /> </p> <p>Second Parent's First Name: <input name="first2" type="varchar" id="first2" /> </p> <p>Parent's Last Name: <input name="last2" type="varchar" id="last2" /> </p> <p>Home Phone: <input name="homephone" type="varchar" id="homephone" /> </p> <p>Cell Phone: <input name="cellphone" type="varchar" id="cellphone" /> </p> <p>Work Phone: <input name="workphone" type="varchar" id="workphone" /> </p> <p>E-Mail Address: <input name="email" type="varchar" id="email" /> </p> <input type="submit" name="Submit" value="Submit" /> </form> </body> </html> And the code for contacts_insert.php <?php $host="***removed***"; $user="***removed***"; $password="***removed***"; $database="contacts"; mysql_connect($host,$user,$password)or die("Can not connect DB"); @mysql_select_db($database) or die( "Unable to select database"); $first=$_POST['first']; $last=$_POST['last']; $first2=$_POST['first2']; $last2=$_POST['last2']; $homephone=$_POST['homephone']; $cellphone=$_POST['cellphone']; $workphone=$_POST['workphone']; $email=$_POST['email']; mysql_query("INSERT INTO contacts(first, last, first2, last2, homephone, cellphone, workphone, email) values('$first','$last','$first2','$last2','$homephone','$cellphone','$workphone','$email')"); mysql_close(); ?> Here is the SHOW CREATE TABLE information: Table Create Table contacts CREATE TABLE `contacts` ( `id` int(6) NOT NULL auto_increment, `first` varchar(30) NOT NULL, `last` varchar(30) NOT NULL, `first2` varchar(30) NOT NULL, `last2` varchar(30) NOT NULL, `homephone` varchar(20) NOT NULL, `cellphone` varchar(20) NOT NULL, `workphone` varchar(20) NOT NULL, `email` varchar(30) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 and the EXPLAIN data: Generation Time: Apr 22, 2009 at 11:59 AM Generated by: phpMyAdmin 2.11.9.4 / MySQL 5.0.67.d7-ourdelta-log SQL query: EXPLAIN contacts ; Rows: 9 Field Type Null Key Default Extra id int(6) NO PRI NULL auto_increment first varchar(30) NO NULL last varchar(30) NO NULL first2 varchar(30) NO NULL last2 varchar(30) NO NULL homephone varchar(20) NO NULL cellphone varchar(20) NO NULL workphone varchar(20) NO NULL email varchar(30) NO NULL I'm sure I missed something simple and will subsequently feel like an idiot when it has been pointed out to me...but I'm willing to risk it and would appreciate any help you could offer me. Quote Link to comment https://forums.phpfreaks.com/topic/155228-submitting-a-form-does-not-add-data-to-mysql-database/ Share on other sites More sharing options...
fenway Posted April 22, 2009 Share Posted April 22, 2009 Well, you're never pulling back the data... how do you know it's not being added? Quote Link to comment https://forums.phpfreaks.com/topic/155228-submitting-a-form-does-not-add-data-to-mysql-database/#findComment-816668 Share on other sites More sharing options...
brokenshadows Posted April 22, 2009 Author Share Posted April 22, 2009 I look at the table in phpmyadmin and there is nothing new added... I might be misunderstanding what you're asking though... Quote Link to comment https://forums.phpfreaks.com/topic/155228-submitting-a-form-does-not-add-data-to-mysql-database/#findComment-816670 Share on other sites More sharing options...
fenway Posted April 22, 2009 Share Posted April 22, 2009 Well, you're not checking the return value of the mysql_query() call, nor capturing mysql_error() -- nor echoing the actual insert statement itself. Quote Link to comment https://forums.phpfreaks.com/topic/155228-submitting-a-form-does-not-add-data-to-mysql-database/#findComment-816808 Share on other sites More sharing options...
brokenshadows Posted April 22, 2009 Author Share Posted April 22, 2009 and i have no idea how to do any of that...like I said, I'm completely new to this Quote Link to comment https://forums.phpfreaks.com/topic/155228-submitting-a-form-does-not-add-data-to-mysql-database/#findComment-816819 Share on other sites More sharing options...
fenway Posted April 22, 2009 Share Posted April 22, 2009 The php refman is your friend. Quote Link to comment https://forums.phpfreaks.com/topic/155228-submitting-a-form-does-not-add-data-to-mysql-database/#findComment-816824 Share on other sites More sharing options...
forbidden18 Posted April 28, 2009 Share Posted April 28, 2009 i look the code,, then i like to give thanks for sharing that codes,,great.. Quote Link to comment https://forums.phpfreaks.com/topic/155228-submitting-a-form-does-not-add-data-to-mysql-database/#findComment-820845 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.