Jump to content

Recommended Posts

Sorry to bother you guys once more, but my script is not working at all, it is suppose to check to see if the user picked the winner, if so add the points, from the points table.

 

Well I tested it, I made the user pick the winner, and it does not add the points at all.

Here is a code snippet, could someone read over it and tell me if I have any syntax errors.

<?php
$result=mysql_query('SELECT * FROM userpoints');

while($row = mysql_fetch_array($result)){
$user = $row['username']; 


   /*Pull Winners for Round 1*/
  $q = mysql_query("Select * from `rnd1_win`");
  $win=mysql_fetch_array($q);
   
  /*Pull User Picks for Round 1*/
  $q = mysql_query("Select * from `rnd1` where `username` = '$user'");
  $pick=mysql_fetch_array($q);
  
  /*Pull Point Values for Round 1*/
  $q = mysql_query("Select rnd1 from `points`");
  $point=mysql_fetch_array($q);
  $value = $point['rnd1'];
  
  /*Pull User Points for Round 1*/
  $q = mysql_query("Select `username`, `total`, `rnd1` from `userpoints` Where `username` = '$user'");
  $usrpoint=mysql_fetch_array($q);
  $total = $usrpoint['total'];
  $rnd1 = $usrpoint['rnd1'];
     
  
    if (!$a1 == ("emp")){
     if ($win['1'] = ($pick['a1'])){
      $total = $value + $total;
      $rnd1 = $value + $rnd1;
      mysql_query("UPDATE `userpoints` SET `total`='$total', `rnd1`='$rnd1' WHERE `username`='$user'")or die(mysql_error());
 }
   }
}
?>

Breaking Down the If Statement

 

    if (!$a1 == ("emp")){ check to see if the postdata is equal to emp, and if not continue the script, if so skip this portion and continue to next if.

    if ($win['1'] = ($pick['a1'])){ check to see if the user picked the winner, if so continue to add points

      $total = $value + $total; take value from point table, and add it to the total, then get a new total

      $rnd1 = $value + $rnd1; take the value from the point table, and add it to round one (rnd1) then get new rnd1

      mysql_query("UPDATE `userpoints` SET `total`='$total', `rnd1`='$rnd1' WHERE `username`='$user'")or die(mysql_error()); update the DB

}

  } Close if statements

 

-Thanks Guys!

 

 

Link to comment
https://forums.phpfreaks.com/topic/94190-need-some-help-on-ifs-and-else/
Share on other sites

I think I fixed it, I just changed the position of the !

 

would this work?

 

<?php
    if ($a1 != ("emp")){
     if ($win['1'] = ($pick['a1'])){
      $total = $value + $total;
      $rnd1 = $value + $rnd1;
      mysql_query("UPDATE `userpoints` SET `total`='$total', `rnd1`='$rnd1' WHERE `username`='$user'")or die(mysql_error());
 }
   }
?>

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.