tags:

views:

74

answers:

2

I have two fields... one is category name and other is document title... When i click on submit... the document title should be saved in document table linking to the category name selected... which is in other table.

A category can have n number of document titles...

 $result = mysql_query("UPDATE stinky_menu SET description  = '$docuTitle', url = '$linkTitle' WHERE title = '$catID'");

How can i perform another query to my other table to in WHERE clause.

+1  A: 

Generally I handle this kind of case by having the select box in the HTML form return the Category ID, not the title. That allows me to insert or update the record without the need for an additional lookup to my reference tables (in this case your category table).

acrosman
+1  A: 

Using :named form for the parameters (?-form also works of course), simplest way to do what you want is to use a FROM and JOIN in your UPDATE -- something like (depending on some details you haven't provided):

UPDATE stinkymenu
SET description = :docuTitle, url = :linkTitle
FROM stinkymenu
JOIN categorytable
ON stinkymenu.catId = categorytable.id
WHERE categorytable.title = :catId

See PDO's docs for the way to use such a "prepared statement" and bind its parameters to your variables.

Alex Martelli