dlindsey Posted September 23, 2009 Share Posted September 23, 2009 I'm getting a syntax error on my insert query and I can't seem to figure it out for the life of me. Maybe one of you could help me out? $sql = "insert into units (address_id, type, number, rent, sqfeet, deposit, key, cleaning, pet, ". "bedrooms, utilities, baths, levels, parking, pool, appliance, yard, furniture, views, ". "other1, other2, other3, other4, other5) values (". "'".$_POST['unit_property_code']."', ". "'".$_POST['unit_type']."', ". "'".$_POST['unit_number']."', ". $_POST['unit_rent'].", ". $_POST['unit_sqfeet'].", ". $_POST['unit_deposit'].", ". $_POST['unit_key'].", ". $_POST['unit_cleaning'].", ". $_POST['unit_pet'].", ". "'".$_POST['unit_bedrooms']."', ". "'".$_POST['unit_utilities']."', ". "'".$_POST['unit_baths']."', ". "'".$_POST['unit_levels']."', ". "'".$_POST['unit_parking']."', ". "'".$_POST['unit_pool']."', ". "'".$_POST['unit_appliance']."', ". "'".$_POST['unit_yard']."', ". "'".$_POST['unit_furniture']."', ". "'".$_POST['unit_views']."', ". "'".$_POST['unit_other1']."', ". "'".$_POST['unit_other2']."', ". "'".$_POST['unit_other3']."', ". "'".$_POST['unit_other4']."', ". "'".$_POST['unit_other5']."')"; print $sql."<br />"; $result = mysql_query($sql, $cn) or die(mysql_error()); And the error page, along with the printed sql query is: insert into units (address_id, type, number, rent, sqfeet, deposit, key, cleaning, pet, bedrooms, utilities, baths, levels, parking, pool, appliance, yard, furniture, views, other1, other2, other3, other4, other5) values ('AVE246', 'single', '', 1.00, 2.00, 3.00, 4.00, 5.00, 6.00, 'a', 'b', 'd', 'e', 'g', 'h', 'j', 'k', 'm', 'n', 'c', 'f', 'i', 'l', 'o') 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 'key, cleaning, pet, bedrooms, utilities, baths, levels, parking, pool, appliance' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/175292-solved-php-mysql-insert-error/ Share on other sites More sharing options...
dlindsey Posted September 24, 2009 Author Share Posted September 24, 2009 Figured it out on my own, figured I'd follow up in case anyone else ever runs into this problem. PHP/MySQL were confused on my field titled 'key', changed the name of it and all was fine. Quote Link to comment https://forums.phpfreaks.com/topic/175292-solved-php-mysql-insert-error/#findComment-923867 Share on other sites More sharing options...
PFMaBiSmAd Posted September 24, 2009 Share Posted September 24, 2009 That's because it is a reserved word and should not be used as a column name - http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html Quote Link to comment https://forums.phpfreaks.com/topic/175292-solved-php-mysql-insert-error/#findComment-923873 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.