通过不在一个实例中工作的php站点将值从一个数据库字段传输到另一个数据库字段

时间:2012-08-21 02:28:43

标签: php mysql

我们的网站上有一个系统,您可以拥有多个帐户并在每个帐户上获得积分。您可以在此网页上的帐户之间转移的那些点我发现错误。基本上,如果我有一个特定的帐户组合,即第一个和第二个,它不会让我转移,它只会说“请填写一个数字。”。如果我有第一个,第三个或全部三个,它可以正常工作。我现在已经查看了大约两个小时,找不到什么不起作用...任何帮助都会立即感激:D

  <?php if($a == "exchange")

  {
  $GetUserInfo = mysql_query("SELECT * FROM members WHERE id = '$userid'") or die(mysql_error());

    $GetUserInfo = mysql_fetch_object($GetUserInfo);

    $cols = 1; //determines colspan
    $status = 1;

    $GetMultipleInfo = mysql_query("SELECT * FROM members WHERE id = '".$GetUserInfo->mult_uid."'") or die(mysql_error());  
      if(mysql_num_rows($GetMultipleInfo) != 0)
      {
        ++$cols;
        ++$status;
      }
      $GetMultipleInfo = mysql_fetch_object($GetMultipleInfo);



    $GetAdMultipleInfo = mysql_query("SELECT * FROM members WHERE id = '".$GetUserInfo->mult_admin."'") or die(mysql_error());
      if(mysql_num_rows($GetAdMultipleInfo) != 0)
      {
        ++$cols;
        $status = ($status == 2 ? 4 : 3);
      }
      $GetAdMultipleInfo = mysql_fetch_object($GetAdMultipleInfo);


// Sparks Transfer
if (isset($_POST['spartrans']))
{
  $order = $_POST['sparrecipients'];

if ($order == 'first')
{
  $tpoints2 = $_POST['tpoints2'];
  $tpoints3 = $_POST['tpoints3'];
  $tpoints = $tpoints2 + $tpoints3;

   if ($status == 2)
      if ((!is_numeric($tpoints1)) || (!is_numeric($tpoints2)) || empty($tpoints1) ||  empty($tpoints2))
        message("Please fill in with a number.","Enchanted Hogwarts","$PHP_SELF?a=exchange");
  elseif ($status == 3)
      if ((!is_numeric($tpoints1)) || (!is_numeric($tpoints3)) || empty($tpoints1) || empty($tpoints3))
        message("Please fill in with a number.","Enchanted Hogwarts","$PHP_SELF?a=exchange");
  elseif ($status == 4)
      if ((!is_numeric($tpoints1)) || (!is_numeric($tpoints2)) || (!is_numeric($tpoints3)) || empty($tpoints1)  ||  empty($tpoints2) || empty($tpoints3))
        message("Please fill in with a number.","Enchanted Hogwarts","$PHP_SELF?a=exchange");

  if ($tpoints2 > $GetMultipleInfo->tpoints)
    message("" . getName($GetMultipleInfo->id) . " does not have enough sparks.","Enchanted Hogwarts","$PHP_SELF?a=exchange");

  if ($tpoints3 > $GetAdMultipleInfo->tpoints)
    message("" . getName($GetAdMultipleInfo->id) . " does not have enough sparks.","Enchanted Hogwarts","$PHP_SELF?a=exchange");

  if ($GetUserInfo->mult_uid != 0)
    mysql_query("UPDATE members SET tpoints = GREATEST(tpoints - $tpoints2,0) WHERE id = '".$GetMultipleInfo->id."'") or die(mysql_error());
  if ($GetUserInfo->mult_admin != 0)
    mysql_query("UPDATE members SET tpoints = GREATEST(tpoints - $tpoints3,0) WHERE id = '".$GetAdMultipleInfo->id."'") or die(mysql_error());
  mysql_query("UPDATE members SET tpoints = GREATEST(tpoints + $tpoints,0) WHERE id = '$userid'") or die(mysql_error());

  message("Successfully transferred $tpoints Sparks to ".getName($userid).".","Enchanted Hogwarts","$PHP_SELF?a=exchange");
}

}

}
?>

1 个答案:

答案 0 :(得分:0)

在你的代码中,你要建立几个变量。

if ($order == 'first')
{
    $tpoints2 = $_POST['tpoints2'];
    $tpoints3 = $_POST['tpoints3'];
    $tpoints = $tpoints2 + $tpoints3;

但接下来你要检查不同变量的值。 $ tpoints1 从未成立过。

if ((!is_numeric($tpoints1)) || (!is_numeric($tpoints2)) || empty($tpoints1) ||  empty($tpoints2))
          message("Please fill in with a number.","Enchanted Hogwarts","$PHP_SELF?a=exchange");
编辑:这可能不正确。你可能有register_globals,它会自动设置该变量。不推荐,但不是你问的问题。

您需要确定代码的哪个分支正在执行的底线。我根据您的描述猜测,它是 $ order == first 分支,然后 $ status == 3 。但是,如果没有实际提交表格并知道做出哪些选择,我就无法说出来。并且所有错误消息都是相同的“请用数字填写”。不是很有帮助。

我个人会花时间重构一些代码。如果我不明白的话,我会将它拆分成更小的块,直到我这样做。否则,每当出现问题时,你都会一直在浏览这个页面。

$ order的每个选择都以完全相同的方式验证$ tpoints1,$ tpoints2和$ tpoints3的值。首先将其移动到一个函数中并从那里开始。