Sefket Posted December 8, 2010 Share Posted December 8, 2010 MySQL 5.1.52 I made a table for "Register" and I have 2 fields for "City/State/Zip". The database doesn't allow duplicates so I made two different field names instead. I then used this site ( http://teamtutorials.com/web-development-tutorials/php-tutorials/inserting-data-into-a-mysql-database-using-php ) and made a form and a updater. I did the script so it calls the two database names and uses it with City/State/Zip in the PHP so it works. Instead I get this: Error updating database Code: <?php $CZip = $_POST['CZip']; $CZip = $_POST['CZip']; mysql_connect ("localhost", "dbuser", "dbpass") or die ('Error: ' . mysql_error()); mysql_select_db ("dbname"); $query="INSERT INTO Register (ID, CZip, CZip, PHON)VALUES ('NULL', '". $CZip."', '".$CZip"', '".$PHON."')"; mysql_query($query) or die ('Error updating database'); echo "Database Updated With: " .$CZip. " ".$CZip." ".$PHON ; ?> Censored the database information. Links : http://evaluationetwork.com/update.php http://evaluationetwork.com/form.php We attempted to use php to access MySQL and update some tables with it. I'm not sure if this link would help : http://codepad.org/BR1If1zC Quote Link to comment https://forums.phpfreaks.com/topic/220990-error-updating-database/ Share on other sites More sharing options...
Buddski Posted December 8, 2010 Share Posted December 8, 2010 I dont really understand why you have 2 fields named the same that both will be storing the same data? Can you explain this in a little more detail? Can you also show us the actual table structure of 'Register'? And last but not least..Change this mysql_query($query) or die ('Error updating database'); to mysql_query($query) or die ('Error updating database because: '.mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/220990-error-updating-database/#findComment-1144325 Share on other sites More sharing options...
Sefket Posted December 8, 2010 Author Share Posted December 8, 2010 I dont really understand why you have 2 fields named the same that both will be storing the same data? Can you explain this in a little more detail? Can you also show us the actual table structure of 'Register'? And last but not least..Change this mysql_query($query) or die ('Error updating database'); to mysql_query($query) or die ('Error updating database because: '.mysql_error()); There is a registration page. It requires City/State/Zip for Physical Address and Payment information. The database doesn't allow duplicates, so I named it two different names. Here is the table structure: http://img834.imageshack.us/img834/7186/screenshot1190.png Pay city and Phys_city is part of City/Zip/State. As you I mentioned before for Physical Address and Payment information. I changed the code as you said, now I got this: Error updating database because: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[Register] (ID, CZip, CZip, PHON)VALUES ('NULL', '..', '.', '..')' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/220990-error-updating-database/#findComment-1144329 Share on other sites More sharing options...
Buddski Posted December 8, 2010 Share Posted December 8, 2010 Ok. Apart from your field names being very complicated (Consider reading up on database construction and their field types) The issue is, you are trying to insert data into fields that do no exist.. Here is an example of how you should enter the values into the database $sql = "INSERT INTO `Register` (`Pay_city`,`Phy_city`) VALUES ('".$CZip."','".$CZip."')"; The first bracket set lists the field names in the table and the second set are the values.. Also consider to protect your sql queries by escaping your input code using mysql_real_escape_string() Quote Link to comment https://forums.phpfreaks.com/topic/220990-error-updating-database/#findComment-1144346 Share on other sites More sharing options...
Sefket Posted December 8, 2010 Author Share Posted December 8, 2010 I just got this error: Error updating database because: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Register' (ID, Pay_city, Phy_city, PHON)VALUES ('NULL', '..', '.', '..')' at line 1 After I did as what you said to do. Quote Link to comment https://forums.phpfreaks.com/topic/220990-error-updating-database/#findComment-1144551 Share on other sites More sharing options...
fenway Posted December 8, 2010 Share Posted December 8, 2010 Your table name looks single-quoted, not in backticks. Quote Link to comment https://forums.phpfreaks.com/topic/220990-error-updating-database/#findComment-1144694 Share on other sites More sharing options...
Buddski Posted December 8, 2010 Share Posted December 8, 2010 Apart from what fenway has said.. You are still trying to insert values into fields that do not exist in your database structure.. I checked and re-checked your screenshot and I do not see a PHON or ID field in your table.. Quote Link to comment https://forums.phpfreaks.com/topic/220990-error-updating-database/#findComment-1144701 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.