ronaldb103 Posted February 16, 2010 Share Posted February 16, 2010 I'm sure this has been asked many times but I can't seem to find a solution when I search the forums. I can get my insert.php to connect to the database but it won't insert into the table. Am I missing something? <form action="insert.php" method="post"> First Name: <input type="text" name="first"><br> Last Name: <input type="text" name="last"><br> Phone: <input type="text" name="phone"><br> Mobile: <input type="text" name="mobile"><br> Fax: <input type="text" name="fax"><br> E-mail: <input type="text" name="email"><br> Web: <input type="text" name="web"><br> <input type="Submit"> </form> <? $username="antondad"; $password="Ruthholmes1"; $database="antondad"; $first=$_POST['first']; $last=$_POST['last']; $phone=$_POST['phone']; $mobile=$_POST['mobile']; $fax=$_POST['fax']; $email=$_POST['email']; $web=$_POST['web']; mysql_connect("antondad.db.4161444.hostedresource.com",$username,$password); @mysql_select_db($database) or die( "Unable to select database"); echo 'Connected successfully'; mysql_query($query); $query = "INSERT INTO contacts ('','$first','$last','$phone','$mobile','$fax','$email','$web')"; mysql_query($query) or die ( 'Unable to update databae'); echo "Database updated with " .$first. "" .$last. "" ; mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/192206-insert-into-table/ Share on other sites More sharing options...
idontkno Posted February 16, 2010 Share Posted February 16, 2010 You're lacking the columns that the values go into. I would also remove your username/password/database location. Quote Link to comment https://forums.phpfreaks.com/topic/192206-insert-into-table/#findComment-1012902 Share on other sites More sharing options...
Aro Posted February 16, 2010 Share Posted February 16, 2010 You didn't define the column names try: $query = mysql_query("INSERT INTO table_name (column1,column2,column3) VALUES ('$var1','var2','$var3')") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/192206-insert-into-table/#findComment-1012917 Share on other sites More sharing options...
ronaldb103 Posted February 16, 2010 Author Share Posted February 16, 2010 Thanks that worked. Quote Link to comment https://forums.phpfreaks.com/topic/192206-insert-into-table/#findComment-1012922 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.