Jump to content

MySQL, PHP, Math - Help


Lamez

Recommended Posts

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";
}
?>

 

Link to comment
Share on other sites

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";
}
?>


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.