Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie quickie,,update followed by select

Status
Not open for further replies.

wudz

Programmer
Mar 28, 2001
135
GB
Hi,
Are you allowed to follow UPDATE with SELECT as the UPDATE works OK, but I can not extract the info in pur_credit field, data is in the db though or is my code wrong?


<code>
$query = "UPDATE AUCTION_purchcredit
SET ver_date = '$VERIFIEDATE',
pp_verified = 'y',
flag='n'
WHERE user_id='".$_SESSION["AUCTION_LOGGED_IN"]."'
ORDER BY id DESC LIMIT 1";

$res = mysql_query($query);
if(!$res) {
MySQLError($query);
exit;
}

//get amount of credit purchased
$query = "SELECT pur_credit FROM AUCTION_purchcredit
WHERE user_id = '".$_SESSION["AUCTION_LOGGED_IN"]."' AND flag='n'";

$res = mysql_query($query);
if(!$res) {
MySQLError($query);
exit;
}
$credit_purchased = $res;
</code>

Cheers in anticipation..
John
 
$res is just a result set, you need to use either mysql_fetch_asoc or mysql_fetch_array to get something coherent out of that variable, purely assigning it to another variable will do nothing.

Try something like:
Code:
$row=mysql_fetch_array($res);

and then

echo $row['pur_credit'];

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
When you run a SELECT query through mysql_query(), the function returns a handle to the data returned, not the data itself. The data isn't directly available but has to be access through the handle. It's very much like a handle to a file returned by fopen().

I think you need to read the PHP online manual entry for mysql_fetch_assoc():
Pay particular attention to the example code.




Want the best answers? Ask the best questions! TANSTAAFL!
 
Great and thanks, been lucky up to now then always thought the function returned the data...makes sense now...

Thanks all

John now with reading glasses ready..

Ps and the speed of the reply
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top