Page 1 of 1

Selecting/using primary key issue

Posted: Mon Feb 05, 2007 12:39 pm
by skyrise85
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


In my form I have a dropdown box, in which the user will select an option and that option will be deleted from the table.  I also have a something similar setup for editing one of the options.  I think I'm having trouble with my SQL code.  Thanks for looking!

Code: Select all

case "edit":
		$tempCat = stripslashes($_POST['eBox']);
		echo "$tempCat<br>";
		
               //this statement runs but I don't think it's pulling the id
                $currentCat = mysql_query("SELECT `genreId` FROM `genre` WHERE `desc`='$tempCat'")
		or die(mysql_error());
		echo "$currentCat<br>";
		
                //editCat is a textfield where the user can make their change to the item in the dropdown
                $eCat = stripslashes($_POST['editCat']);
		$result = mysql_query("UPDATE `genre` SET desc='$eCat' WHERE genreID='$currentCat'") 
		or die("edit statement error<br>"); 
		echo "$result";
		break;	
	case "delete":
		$tempCat = stripslashes($_POST['dBox']);
		echo "$tempCat";
		$result = mysql_query("DELETE FROM genre WHERE desc='$tempCat'") 
		or die("delete statement error<br>");
		echo "$result";
		break;
If I run the edit I get:
*selected option from dropdown*
Resource id #3
edit statement error

If I run the delete I get:
*selected option from dropdown*
edit statement error


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Feb 05, 2007 2:36 pm
by boba
Hi,
Everything you can do to resolve your problem is to read php manual with high attention.
Take a look here: http://ua.php.net/mysql_fetch_assoc
Your problem is in MySQL functions use. See example described there.

Posted: Mon Feb 05, 2007 2:59 pm
by Ollie Saunders
mysql_query() returns a result resource which you have to use with mysql_fetch_assoc() to get the data you need.