简单的PHP投票系统不会更新数据库

时间:2013-02-09 23:27:55

标签: php mysql database

<?php
session_start();
$host        =    'localhost';
$user        =    'root';
$password    =    '8******8';
$database    =    'tg*****ba';

$conn = mysql_connect($host,$user,$password) or 
  die('Server Information is not Correct'); 

//Establish Connection with Server
mysql_select_db($database,$conn) or die('Database Information is not correct');
$InGameName    =    mysql_real_escape_string($_POST['InGameName']);
$LastVoteTime;

//===When I will Set the Button to 1 or Press Button to register
if(isset($_POST['btnVote'])) 
{
  if(md5($_POST['code']) != $_SESSION['key']) 
    die("You've entered a wrong code!");
  $query = mysql_query("SELECT * FROM entities WHERE Name = '". $InGameName ."'"); 
  if (mysql_num_rows($query) < 0) 
  { 
     die("This In game name doesn't exist , please enter your account name not username!");
  }
  else
  {
    $date = date('YmdHis');
    $row=mysql_fetch_object($query);
    $lastvote=$row->LastVoteTime;
    $votingpoints = $row->VotsPoints;
    $url = "http://www.xtremetop100.com/in.php?site=***********";

    if(($lastvote + 120000) < $date)
    {
      $lastvote = $date;
      $votingpoints += 1;
      $query = mysql_query("update entities set VotsPoints ='$votingpoints' set LastVoteTime ='$lastvote' WHERE Name = '". $InGameName ."'"); 
    }
    else
      die("You've Already voted in the last 12 hrs!");
  }
}

?>

它不会使用投票点和lastvotetime更新数据库 但是它通过了第一次检查(这意味着它在数据库中找到了帐户记录)但它没有在代码的末尾设置它们 提前谢谢

2 个答案:

答案 0 :(得分:2)

尝试:

$query = mysql_query("update entities set VotsPoints = '$votingpoints', LastVoteTime = '$lastvote' WHERE Name = '". $InGameName ."'");

您多次使用“设置”,不确定是否可以。

答案 1 :(得分:0)

您的SQL语法在UPDATE语句中不正确。 http://dev.mysql.com/doc/refman/5.0/en/update.html