tags:

views:

57

answers:

3
function saveFile($catId,$docuTitle,$linkTitle) {

 $result = mysql_query("INSERT INTO categories (cd_title, cd_link)
                       VALUES ('$docuTitle','$linkTitle') WHERE c_name = '$catID'");    

      return 'yes';

     }

I want to insert the cd title and cd links based on the catergory selected.

+2  A: 

Edit: Scott Saunders is right, you can't have a WHERE statement in an INSERT query.

Original answer: You should give more info about the error, but you probably have a simple quote (') in on of the variables $docuTitle or $linkTitle, resulting in a malformed query.

You should escape these variables, as well as $catId, with mysql_real_escape_string() before using them in requests, or else your app will be vulnerable to SQL Injection.

You should read some docs about PDO, it is a great tool to avoid this kind of mistakes in SQL queries, and it helps a lot for evolutivity and maintainability.

FWH
+1 for PDO [+1 I say!]
anonymous coward
+2  A: 

You probably want:

INSERT INTO categories (cd_title, cd_link, c_name) VALUES ('$docuTitle','$linkTitle', '$catID')

Unless you're updating existing rows, then change 'INSERT INTO' to 'UPDATE'

Scott Saunders
jea INSERT and WHERE in the same statement makes no sense
Flo
+1  A: 

you are combining an INSERT statement and an UPDATE statement.

You need to choose the correct syntax:

INSERT INTO [TABLE] [COLUMNS] VALUES [VALUES]

UPDATE [TABLE] SET [COLUMNS] = [VALUE] WHERE [where clause]
northpole