Jump to content

non-working elseif statements


kaozdragon

Recommended Posts

$result = mysql_query("SELECT * FROM signup");
$row = mysql_fetch_array($result);
$increase = mysql_query("UPDATE signup SET hot = hot+1 ");
$username = $_COOKIE['username'];
$adduser = mysql_query("UPDATE signup SET hotname ='$username'");
$adduser2 = mysql_query("UPDATE signup SET hotname2 ='testing2'");

if ($row['hot']==0)
{
$increase;
$adduser;
echo "User has been increased to " . $row['hot'] . " and the user, " . $row['hotname'] . " has been added. <a href='signup.php'>Signup again</a>";
mysql_close($con);
}

elseif ($row['hot']==1)
{
$increase;
$adduser2;
echo "User is now at " . $row['hot'] . " and the user " .$row['hotname2'] . "has been added.  <a href='signup.php'>Go back</a>";
mysql_close($con);
}

else
{
echo "full up, sorry.";
}

 

for some reason, even when $row['hot'] is set to 0 in the table, it will add both adduser and adduser2.  any help would be appreciated, thanks.

Link to comment
Share on other sites

kaoz, you have a misconception about how variables work.  This code actually executes the query, storing the result in $adduser

 

$adduser = mysql_query("UPDATE signup SET hotname ='$username'");

 

Later when you write "$adduser;", that does nothing at all.  The query was already executed.

 

So to fix it, you just need to move those mysql_query() calls inside the if/else :)

 

All 3 queries should go inside, replacing "$increase;", "$adduser;" and "$adduser2"

Link to comment
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.