Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question about inserting data into database

Status
Not open for further replies.

DataSpy

Technical User
Nov 15, 2002
39
US
I'm trying to do something like this
Code:
$query="INSERT INTO ".$table_name." ('catagory', 'link', 'link_description', 'link_title', 'link_name',) 
VALUES ('', '".$link."', '', '', '') WHERE catagory=".$catagory."";
I know this isn't right, I just don't know how to do what I want. Any help would be greatly appretiated!
 
Try printing the query and see if you can tell what you've done wrong.

The most obvious thing is your column names shouldn't be in single quotes.
 
The column names are fine. The only problem I'm having is with WHERE catagory=".$catagory."";, that's not allowed in the insert syntax but that is what I want to do. I want insert the link into a certain column I just don't know how to do it. Everything else is fine, if I take out WHERE catagory=".$catagory."";, everything is ok. But I want to be able to insert everything into a certain catagory. Thanx for the help though.
 
A where in an insert doesn't make any sense. Perhaps you mean UPDATE?

P.S.
Quotes around your column names are invalid SQL syntax. Perhaps your scripting language is allowing you to get by with incorrect SQL, but it's still wrong.

Code:
mysql> desc thing;
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| col1  | varchar(255) | YES  |     | NULL    |       |
+-------+--------------+------+-----+---------+-------+
1 row in set (0.00 sec)
 
mysql> insert into thing ( 'col1' ) values ( '1' );
ERROR 1064 (42000): 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 ''col1' ) values ( '1' )' at line 1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top