plutomed Posted July 4, 2009 Share Posted July 4, 2009 When inserting into a database, do you have to specify all the column names? Because I get the error: 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 'order) mysql_query("INSERT INTO UserCP(name, link_name, content, order) VALUES('".$_POST['name']."','".$_POST['lname']."','".$_POST['content']."','".($order[0] -1).")") or array_push($error_array, "ERROR08 - ".mysql_error()); Table: CREATE TABLE IF NOT EXISTS `UserCP` ( `id` int(11) NOT NULL auto_increment, `name` varchar(30) NOT NULL default '', `link_name` varchar(30) NOT NULL default '', `content` text NOT NULL COMMENT 'If first line isn''t php add ?> to the start.', `enabled` int(11) NOT NULL default '1', `order` int(11) NOT NULL default '0', PRIMARY KEY (`id`) ) Is i because I haven't specified the column enabled?? Quote Link to comment https://forums.phpfreaks.com/topic/164792-solved-inserting-into-a-database/ Share on other sites More sharing options...
MadTechie Posted July 4, 2009 Share Posted July 4, 2009 try this mysql_query("INSERT INTO UserCP(name, link_name, content, `order`) VALUES('".$_POST['name']."','".$_POST['lname']."','".$_POST['content']."','".($order[0] -1)."')") or array_push($error_array, "ERROR08 - ".mysql_error()); Added last ' and used back ticks on order field Quote Link to comment https://forums.phpfreaks.com/topic/164792-solved-inserting-into-a-database/#findComment-868978 Share on other sites More sharing options...
plutomed Posted July 4, 2009 Author Share Posted July 4, 2009 Yea that fixed it. ??? How come that made a difference?? Quote Link to comment https://forums.phpfreaks.com/topic/164792-solved-inserting-into-a-database/#findComment-868980 Share on other sites More sharing options...
MadTechie Posted July 4, 2009 Share Posted July 4, 2009 okay you missed the last ' so the values were like this VALUES ('123', 'abc','blar) note the missing ' also ORDER is a reserved word, so you can't use it, unless you tell MySQL its a field by enclosing it in backticks Quote Link to comment https://forums.phpfreaks.com/topic/164792-solved-inserting-into-a-database/#findComment-868986 Share on other sites More sharing options...
plutomed Posted July 5, 2009 Author Share Posted July 5, 2009 Yea I noticed the ' in the end. Ahh ok. I get where and when I have to use the ` now. Thanx. Quote Link to comment https://forums.phpfreaks.com/topic/164792-solved-inserting-into-a-database/#findComment-869014 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.