Jump to content

Recommended Posts

What I want to do, is search a table named "Photos", and compare the current user's ID number (logged in) with the UserID number(s) in the table.  If the current user has contributed photos, I want to set a flag named $PhotoContrib = 1.  Otherwise (default), if they have not contributed photos, $PhotoContrib = 0.  I don't want anything to print out, I just want to set a value to use later.

 

Here's what I have:

 

$PhotoContribQuery = "SELECT DISTINCT UserID FROM Photos ORDER BY UserID";

$PhotoContribResult = mysql_query($PhotoContribQuery) or die(mysql_error());

while ($UserID = mysql_fetch($PhotoContribResult))

if ($SessionUserID = $PhotoContribResult)

{

$PhotoContrib = 1;

}

else

{

$PhotoContrib = 0;

}

 

But I get this:

 

Fatal error: Call to undefined function: mysql_fetch() in /home/locophot/public_html/PhotoContrib.php on line 7.

 

What am I doing wrong?

 

Thanks,

Stan

 

That fixed the fatal error.  To check if the query was working correctly, I added echos:

 

if ($SessionUserID = $PhotoContribResult)

{

$PhotoContrib = 1;

echo "user has photos posted.";

}

else

{

$PhotoContrib = 0;

echo "user does not have photos posted.";

}

 

What happens, is that it prints out a list of "user has photos posted." (which would set $PhotoContrib = 1) as it loops through the table.  Since I am not logged in, I don't have a SessionUserID set, so it should at least return "user does not have photos posted.".  Do I need a GET statement somewhere to fetch the current SessionUserID number to compare against the table?

 

Thanks,

Stan

 

I found one thing wrong with the code that you have now.

 

if ($SessionUserID == $PhotoContribResult) {
   $PhotoContrib = 1;
   echo "User has photos posted.";
}
else {
   $PhotoContrib = 0;
   echo "User does not have photos posted.";
}

 

If you only put one equal sign on the first line, the code actually sets the variable to $PhotoContribResult. But since it's in an "if" statement, two equal signs means that the script will actually check if they are equal to each other.

 

As for the session thing, read about it here.

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.