phppatron Posted August 5, 2007 Share Posted August 5, 2007 My file is a learning exercise. It has a simple form, and it uses the inserted data and is supposed to add the data to my simple database. It seems to be collecting the data (at least, if I echo the gathered data it shows properly) - so I don't know why the data is not uploaded. I understand it could be several things - but I don't know where to begin checking. I'm not getting any errors. Here is my file: (I removed the actual user and password and the database name substituted placeholders here) more info: the table has the fields in the form plus one more - ID (set to autoincrement) If nothing is wrong here, where should I begin to look?? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <?php $street = $_POST["street"]; $city = $_POST["city"]; $stateabbr = $_POST["stateabbr"]; $zipcode = $_POST["zipcode"]; ?> <?php $connection = mysql_connect("localhost", "user", "password"); if (!$connection){ die("Could not connect to the database: <br/>" . mysql_error()); } $db_select = mysql_select_db("databasename"); if (!$db_select) { die ("could not select the database: <br />". mysql_error()); } ?> <?php if (!empty($street)&& !empty($city) && !empty($stateabbr) && !empty($zipcode)){ $query="INSERT INTO 'table' VALUES ('$_POST[street]','$_POST[city]','$_POST[stateabbr]',' $_POST[zipcode])"; $result = mysql_query($query); } echo $query; ?> <form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post"> <label> Street: <input type="text" name="street" value="<?php echo $street; ?>"/> </label> <label> City: <input type="text" name="city" value="<?php echo $city; ?>" /> </label> <label> State Abbrev: <input type="text" name="stateabbr" value="<?php echo $stateabbr; ?> "/> </label> <label> Zip Code: <input type="text" name="zipcode" value="<?php echo $zipcode; ?>" /> </label> <input type="submit" value="Submit" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/63392-data-not-being-added/ Share on other sites More sharing options...
tibberous Posted August 5, 2007 Share Posted August 5, 2007 One good debugging trick is to go right below the query, copy whatever is in the query, and then die with it. So, right where you have: $result = mysql_query($query); add below it: echo mysql_error(); die($query); Three things are learned from this. 1) You know the query is getting called. 2) You know the exact values going into it. 3) You know if there are any mysql errors. If that still doesn't work, copy the query and try to put it in PHP myadmin, and see if it acctually does something in mysql. Quote Link to comment https://forums.phpfreaks.com/topic/63392-data-not-being-added/#findComment-315965 Share on other sites More sharing options...
harristweed Posted August 5, 2007 Share Posted August 5, 2007 I think that you need the field names in the query: $query="INSERT INTO 'table' VALUES ('$_POST[street]','$_POST[city]','$_POST[stateabbr]',' $_POST[zipcode])"; should be: $query="INSERT INTO 'table' (street, city, stateabbr, zipcode ) VALUES ('$_POST[street]','$_POST[city]','$_POST[stateabbr]',' $_POST[zipcode])"; Quote Link to comment https://forums.phpfreaks.com/topic/63392-data-not-being-added/#findComment-316032 Share on other sites More sharing options...
Barand Posted August 5, 2007 Share Posted August 5, 2007 Table and column names do not go in quotes. INSERT INTO table ...... Quote Link to comment https://forums.phpfreaks.com/topic/63392-data-not-being-added/#findComment-316035 Share on other sites More sharing options...
Utech22 Posted August 5, 2007 Share Posted August 5, 2007 Correct to these: $street = $_POST['street']; $city = $_POST['city']; $stateabbr = $_POST['stateabbr']; $zipcode = $_POST['zipcode']; $query="INSERT INTO table VALUES ($_POST['street'],$_POST['city'],$_POST['stateabbr'], $_POST['zipcode'])"; Quote Link to comment https://forums.phpfreaks.com/topic/63392-data-not-being-added/#findComment-316158 Share on other sites More sharing options...
phppatron Posted August 5, 2007 Author Share Posted August 5, 2007 thank you to all, with your help I was able to get it working - Quote Link to comment https://forums.phpfreaks.com/topic/63392-data-not-being-added/#findComment-316206 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.