Jump to content

[SOLVED] Inserting into a database :(


plutomed

Recommended Posts

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??

Link to comment
https://forums.phpfreaks.com/topic/164792-solved-inserting-into-a-database/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.