Jump to content

Why isn't this insert working when another is?


Cultureshock

Recommended Posts

In the following code, Inserting into content works but not collectives. Also, when removing content, collectives still does not update.

 

It inserts the details into content then heads straight to /collectives.php?step=2 without adding anything to collectives.

 


mysql_query("INSERT INTO content
(uid, type, title, content, commenting) 
VALUES('$uid', 'coll', '$title', '$desc', 'yes' ) ") or die(mysql_error()) ;

mysql_query("INSERT INTO collectives
(uid, title, desc) 
VALUES('$uid', '$title', '$desc' ) ") ;

header('location:/collectives.php?step=two');

 

Here are the table details:

 

Collective:

cid int(11) auto_increment unique
uid int(11)
title 	varchar(50)
desc 	varchar(150) 
time 	timestamp CURRENT_TIMESTAMP 	

 

I don't see anything wrong with it?

 

LOL, your first query has some error checking and error reporting logic (the or die(mysql_error()) ) to get it to tell you if it failed and why it failed. But your second query does not.

 

If you added that same error checking and error reporting logic to the second query, you would get an sql syntax error at the point where the desc column is listed because desc is a reserved keyword and should not be used as a column name. You should either rename the column to something else or enclose it in back-ticks ` `

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.