Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.