Jump to content

Query problem


SirChick

Recommended Posts

I have a query that is not finding the record when one does exist.. no error occurs but the variable when echo'd always equals 0. Not sure why..

 

This is what i have:

 

$getpaper = "SELECT * FROM useritem WHERE UserID='$_SESSION[Current_User]' And ItemID = '1'"
						or die(mysql_error());
					// Fetch the row from the database
			if (!($paperrow = mysql_fetch_assoc($GetUserID))) {
			$TotalPaper = 0;
			}Else{
			$TotalPaper = $paperrow['Quantity'];
			}

 

$_SESSION[Current_User] is used via a global session carried around via the global include.

Link to comment
https://forums.phpfreaks.com/topic/73347-query-problem/
Share on other sites

$getpaper = "SELECT * FROM useritem WHERE UserID='{$_SESSION['Current_User']}' And ItemID = '1'"
						or die(mysql_error());
					// Fetch the row from the database
			if (!($paperrow = mysql_fetch_assoc($GetUserID))) //Makes no sense!
			{
			$TotalPaper = 0;
			}else{
			$TotalPaper = $paperrow['Quantity'];
			}

 

 

Link to comment
https://forums.phpfreaks.com/topic/73347-query-problem/#findComment-370070
Share on other sites

You're not doing any query.

Also, if you're only using one field, just retrieve that field.

You should be checking to see if any rows are being returned:

<?php
$query = "SELECT Quantity FROM useritem WHERE UserID='$_SESSION[Current_User]' And ItemID = '1'";
$rs = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());
if (mysql_num_rows($rs) != 1)
$TotalPaper = 0;
else {
        $paperrow = mysql_fetch_assoc($rs);
        $TotalPaper = $paperrow['Quantity'];
}
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/73347-query-problem/#findComment-370072
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.