drayarms Posted August 20, 2011 Share Posted August 20, 2011 Hello everybody, I can't seem to figure out why this insert code isn't working. I'm trying to create a database of US zip codes. I created this user interface (form) with nothing but a submit button to execute the insert query <div id="right_content" class=""> <h3> Insert Zips </h3> <form action = "insertzip1.php" method = "post"> <input type = "submit" name = "submit" value = "submit"/> </form> </div> <!--closes right content--> Well here is the insert query which is supposed to accomplish the task. I have just included a tiny subsets of all the zipcodes (the insertzip1.php page which is the value of the action attribute of the form). <php? if (isset($_POST['submit'])) { require ('config.php'); $query = "INSERT INTO zips (zip, lat, lon, city, state, county, z_type, xaxis, yaxis, zaxis, z_primary, worldregion, country, locationtext, location, population, housingunits, income, landarea, waterarea, decommisioned, militaryrestrictioncodes, decommisionedplace) VALUES ('00501', 40.81, -73.04, 'HOLTSVILLE', 'NY', 'SUFFOLK', 'UNIQUE', 0.22, -0.72, 0.65, 'Yes', 'NA', 'US', 'Holtsville, NY', 'NA-US-NY-HOLTSVILLE', '', 0, 0, '', '', 'No', '', ''), ('00501', 40.81, -73.04, 'I R S SERVICE CENTER', 'NY', 'SUFFOLK', 'UNIQUE', 0.22, -0.72, 0.65, 'No', 'NA', 'US', 'I R S Service Center, NY', 'NA-US-NY-I R S SERVICE CENTER', '', 0, 0, '', '', 'No', '', ''), ('00544', 40.81, -73.04, 'HOLTSVILLE', 'NY', 'SUFFOLK', 'UNIQUE', 0.22, -0.72, 0.65, 'Yes', 'NA', 'US', 'Holtsville, NY', 'NA-US-NY-HOLTSVILLE', '', 0, 0, '', '', 'No', '', ''), ('00544', 40.81, -73.04, 'IRS SERVICE CENTER', 'NY', 'SUFFOLK', 'UNIQUE', 0.22, -0.72, 0.65, 'No', 'NA', 'US', 'Irs Service Center, NY', 'NA-US-NY-IRS SERVICE CENTER', '', 0, 0, '', '', 'No', '', '') "; $result = mysql_query($query); header("Location: insertzipsuccess.php"); }else{ die ("Could not insert data because" . mysql_error());} ?> The insertzipsuccess.php page is simply a page that prints out a success message if the query is successfully executed. Well when I hit the submit button, I just get redirected to a blank insertzip1.php page Can anyone show me what I'm not doing right here? PS I already created the table with fields that correspond to all the fields I'm trying insert. Link to comment https://forums.phpfreaks.com/topic/245315-mysql-insert-code-not-working/ Share on other sites More sharing options...
Psycho Posted August 20, 2011 Share Posted August 20, 2011 Just add some simple debugging to see what error is occurring $result = mysql_query($query) or die (mysql_erro()); Link to comment https://forums.phpfreaks.com/topic/245315-mysql-insert-code-not-working/#findComment-1259971 Share on other sites More sharing options...
cunoodle2 Posted August 20, 2011 Share Posted August 20, 2011 I'm not sure at all but I would be willing to be that it has something to do with the commas in some of your field names. The insert statement may think that is the end/start of a new field or something along those lines. I'm not totally sure though.. "'Irs Service Center, NY'," Link to comment https://forums.phpfreaks.com/topic/245315-mysql-insert-code-not-working/#findComment-1259977 Share on other sites More sharing options...
MjM8082 Posted August 21, 2011 Share Posted August 21, 2011 Well your opening for php should be... <?php not <php? Link to comment https://forums.phpfreaks.com/topic/245315-mysql-insert-code-not-working/#findComment-1260007 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.