Query returns "Resource Identifier #6" instead of

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Moonspell
Forum Newbie
Posts: 21
Joined: Tue May 13, 2003 4:54 pm

Query returns "Resource Identifier #6" instead of

Post by Moonspell »

I have a script where I insert data for a customer into a table. The table has a primary key which automatically updates (INT NOT NULL AUTO_INCREMENT). I want to insert a row into the table, and then find out what ID I just inserted.

Here's the first query which inserts data into the ClientSales table.

$secondquery = "INSERT INTO ClientSales (ClientNameID, SalesFName, SalesLName) values ('$theclientid', '$FName','$LName')";
mysql_query($secondquery);

This table has the primary, unique key. The data goes in perfectly, no errors or problems. Now, since I just entered data, I want to find out what number MySQL automatically generated. So, I run this script

$findtheid = "SELECT ClientSalesID FROM ClientSales WHERE SalesFName = '$FName' AND SalesLName = '$LName'";
$findtheidresult = mysql_query($findtheid);

$findtheidresult returns Resource Identifier #6 instead of the data I'm tryin got call. Where is my error?
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Post by Jade »

Quick question...

is this by any chance in a while loop? You might want to try turning you error message on. I get this message all the time, and its usually when i have a script in a while loop where i've named two varibles the exact same thing by accident.

Jade
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

mysql_query() returns a resource identifier not the values themself. You have to use mysql_fetch_... functions to retrieve the values, e.g. mysql_fetch_array() (there are examples on that page)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Re: Query returns "Resource Identifier #6" instead

Post by twigletmac »

Moonspell wrote:This table has the primary, unique key. The data goes in perfectly, no errors or problems. Now, since I just entered data, I want to find out what number MySQL automatically generated.
For this you don't need a second query, you can use mysql_insert_id().

Mac
Moonspell
Forum Newbie
Posts: 21
Joined: Tue May 13, 2003 4:54 pm

Post by Moonspell »

volka wrote:mysql_query() returns a resource identifier not the values themself. You have to use mysql_fetch_... functions to retrieve the values, e.g. mysql_fetch_array() (there are examples on that page)
so:

$result = mysql_query($query);
$arrayresult = mysql_fetch_array($result);

Will that return the data?
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post by Jim »

Generally putting that array into a loop and setting variables equal to table data is what I do.

$query = mysql_query();

while ($info = mysql_fetch_array($query)) {

$id = $info['id'];
$otherstuff = $info['cat'];

}


There's a good tutorial for this at http://www.phpcomplete.com, I know.
Post Reply