bob2588 Posted July 6, 2009 Share Posted July 6, 2009 I cant figure out why thsi code is not working can any one help <?php include "db.php"; $State = $_POST['State']; $zip = $_POST['zip']; $type = $_POST['type']; mysql_connect ("$host" , "$user" , "$pass") or die ('Error; ' . mysql_error()); mysql_select_db ("$db_name"); mysql_query("INSERT INTO real (id, State, zip, Type) Values ( '$State', '$zip', '$type')") or die ('Error updating Databases'); echo"Databases Updated With: .$State .$zip .$type"; Link to comment https://forums.phpfreaks.com/topic/164953-solved-i-should-know-this/ Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 what is breaking? Link to comment https://forums.phpfreaks.com/topic/164953-solved-i-should-know-this/#findComment-869795 Share on other sites More sharing options...
onthespot Posted July 6, 2009 Share Posted July 6, 2009 You are trying to enter 3 times into 4 fields. However, the order isnt correct? Or do you need to enter ID ? You arent entering a value into ID? Link to comment https://forums.phpfreaks.com/topic/164953-solved-i-should-know-this/#findComment-869798 Share on other sites More sharing options...
bob2588 Posted July 6, 2009 Author Share Posted July 6, 2009 the one missing is an auto increment value i took out part of the code while trying to figure out what i was doing wrong It is not inserting the info in to the data base <?php include "db.php"; $State = $_POST['State']; $zip = $_POST['zip']; $type = $_POST['type']; mysql_connect ("$host" , "$user" , "$pass") or die ('Error; ' . mysql_error()); mysql_select_db ("$db_name"); mysql_query("INSERT INTO real (id, State, zip, Type) Values ('null', '$State', '$zip', '$type')") or die ('Error updating Databases'); echo"Databases Updated With: .$State .$zip .$type"; ?> Link to comment https://forums.phpfreaks.com/topic/164953-solved-i-should-know-this/#findComment-869799 Share on other sites More sharing options...
onthespot Posted July 6, 2009 Share Posted July 6, 2009 Where are you getting the POST values from? And whats in db.php? Link to comment https://forums.phpfreaks.com/topic/164953-solved-i-should-know-this/#findComment-869801 Share on other sites More sharing options...
bob2588 Posted July 6, 2009 Author Share Posted July 6, 2009 here is the form <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 2</title> </head> <body> <form method="POST" action="add.php"> <p style="margin-top: 0; margin-bottom: 0"> <input type="text" name="State" size="20"></p> <p style="margin-top: 0; margin-bottom: 0"> <input type="text" name="zip" size="20"></p> <p style="margin-top: 0; margin-bottom: 0"> <input type="text" name="type" size="20"></p> <p style="margin-top: 0; margin-bottom: 0"> <input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p> </form> </body> </html> here is the add.php <?php include "db.php"; $State = $_POST['State']; $zip = $_POST['zip']; $type = $_POST['type']; mysql_connect ("$host" , "$user" , "$pass") or die ('Error; ' . mysql_error()); mysql_select_db ("$db_name"); mysql_query("INSERT INTO real (id, State, zip, Type) Values ('null', '$State', '$zip', '$type')") or die ('Error updating Databases'); echo"Databases Updated With: .$State .$zip .$type"; ?> and last db.php <?php $host = "localhost"; //Databse Location $user = "bob2_search"; //Database User $pass= "skater22"; //Database Password $db_name ="bob2_search"; //Database Name ?> Link to comment https://forums.phpfreaks.com/topic/164953-solved-i-should-know-this/#findComment-869806 Share on other sites More sharing options...
onthespot Posted July 6, 2009 Share Posted July 6, 2009 Have you tested the SQL? In phpmyadmin, test the SQL, replacing the values that are variables with just values that you would enter in the initial form. Try that. Link to comment https://forums.phpfreaks.com/topic/164953-solved-i-should-know-this/#findComment-869813 Share on other sites More sharing options...
bob2588 Posted July 6, 2009 Author Share Posted July 6, 2009 I figure it out the code should look like this <?php include "db.php"; $State = $_POST['State']; $zip = $_POST['zip']; $type = $_POST['type']; mysql_connect ("$host" , "$user" , "$pass") or die ('Error; ' . mysql_error()); mysql_select_db ("$db_name"); mysql_query("INSERT INTO `$db_name`.`real` (id, State, zip, Type) Values ('null', '$State', '$zip', '$type')") or die ('Error updating Databases'); echo"Databases Updated With: .$State .$zip .$type"; ?> i was missing the database name in the mysql insert :/ Link to comment https://forums.phpfreaks.com/topic/164953-solved-i-should-know-this/#findComment-869815 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.