Lamez Posted February 12, 2008 Share Posted February 12, 2008 I have never used math at all in php, this is my first script. This script is suppose to pull the info from the winners table, and the user picks, from the userpicks table, and if the rows are equal then add the points from the points table, to the value in the userpoints table, then add it to the database here is what I have: I do not think it is correct, I just took a shot in the dark with the math, but it does not add it to the database, that is why I am posting. So are there any errors? <?php include ("../../style/include/session.php"); if($session->logged_in){ $user = $session->username; $points = "select * from points"; $uspo = "select * from userpoints"; $win = "select * from winners"; $uspick = "select * from userpicks"; $pnt = mysql_query($points) or die(mysql_error()); $usp = mysql_query($uspo) or die(mysql_error()); $wn = mysql_query($win) or die(mysql_error()); $up = mysql_query($uspick) or die (mysql_error()); $rs = mysql_fetch_array($pnt); $userp = mysql_fetch_array($usp); $winr = mysql_fetch_array($wn); $uspck = mysql_fetch_array($up); if ($uspck['1'] === ($winr['1'])){ $rs['1'] + $userp['total'] = $new; $q = "UPDATE `userpoints` SET `total`=$new WHERE `username`='$user'"; mysql_query($q); echo "You Won ".$rs['1']." points"; echo "You have".$new."total points"; }else{ echo "no win"; } }else{ echo "login"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/90633-mysql-php-math-help/ Share on other sites More sharing options...
gardan06 Posted February 12, 2008 Share Posted February 12, 2008 simple, you got $rs['1'] + $userp['total'] = $new; all backwards. try $new = $rs['1'] + $userp['total']; Quote Link to comment https://forums.phpfreaks.com/topic/90633-mysql-php-math-help/#findComment-464656 Share on other sites More sharing options...
Lamez Posted February 12, 2008 Author Share Posted February 12, 2008 oh I got it, lol just like naming a variable $name = "Jones"; echo $name; Well this is my latest code, wanna look over it for errors? <?php include ("../../style/include/session.php"); if($session->logged_in){ $user = $session->username; $points = "select * from points"; $uspo = "select username WHERE username = $user from userpoints"; $win = "select * from winners"; $uspick = "select * from userpicks"; $pnt = mysql_query($points) or die(mysql_error()); $usp = mysql_query($uspo) or die(mysql_error()); $wn = mysql_query($win) or die(mysql_error()); $up = mysql_query($uspick) or die (mysql_error()); $rs = mysql_fetch_array($pnt); $userp = mysql_fetch_array($usp); $winr = mysql_fetch_array($wn); $uspck = mysql_fetch_array($up); $enc = md5("action"); $r1 = md5("round1"); $r2 = md5("round1"); $r3 = md5("round3"); if ($_GET[$enc] === ($r1)){ if ($userp['1'] === ('0')){ if ($uspck['1'] === ($winr['1'])){ $new = $rs['1'] + $userp['total']; $q = "UPDATE `userpoints` SET `total`=$new, `1`=1 WHERE `username`='$user'"; mysql_query($q); echo "You Won ".$new." points<br>"; echo "You have ".$userp['total']." total points"; }else{ echo "no win"; } }else{ echo "You have already played this round!"; } echo '<br><a href="?">Index</a>'; } elseif ($_GET[$enc] === ($r2)){ if ($userp['2'] === ('0')){ if ($uspck['2'] === ($winr['2'])){ $new = $rs['2'] + $userp['total']; $q = "UPDATE `userpoints` SET `total`=$new, `2`=1 WHERE `username`='$user'"; mysql_query($q); echo "You Won ".$new." points<br>"; echo "You have ".$userp['total']." total points"; }else{ echo "no win"; } }else{ echo "You have already played this round!"; } echo '<br><a href="?">Index</a>'; } elseif ($_GET[$enc] === ($r3)){ if ($userp['3'] === ('0')){ if ($uspck['3'] === ($winr['3'])){ $new = $rs['3'] + $userp['total']; $q = "UPDATE `userpoints` SET `total`=$new, `3`=1 WHERE `username`='$user'"; mysql_query($q); echo "You Won ".$new." points<br>"; echo "You have ".$userp['total']." total points"; }else{ echo "no win"; } }else{ echo "You have already played this round!"; } echo '<br><a href="?">Index</a>'; }else{ echo '<a href=?'.$enc.'='.$r1.'>Round 1</a><br>'; echo '<a href=?'.$enc.'='.$r2.'>Round 2</a><br>'; echo '<a href=?'.$enc.'='.$r3.'>Round 3</a><br>'; echo 'Total Points: '.$userp['total']; echo '<br><a href="standings.php">Standings</a>'; } }else{ echo "login"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/90633-mysql-php-math-help/#findComment-464657 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.