Selecting/using primary key issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
skyrise85
Forum Newbie
Posts: 15
Joined: Fri Jan 19, 2007 5:50 pm

Selecting/using primary key issue

Post 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]
User avatar
boba
Forum Newbie
Posts: 15
Joined: Sun Feb 04, 2007 2:46 pm
Location: Kharkov, Ukraine
Contact:

Post 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.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

mysql_query() returns a result resource which you have to use with mysql_fetch_assoc() to get the data you need.
Post Reply