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
https://forums.phpfreaks.com/topic/41374-non-working-elseif-statements/
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"

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.