谁能告诉我这个页面中的错误是什么?

时间:2011-10-19 16:21:06

标签: php mysql sql

我在这个php文件上得到了这个错误行。有人可以找到错误的位置吗?

-------------您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以便在第1行的''附近使用正确的语法----------

我有这个页面用于投票给用户,但如果我在一个用户投票,这个投票将发送给所有用户。如何在投票时将此代码发送给其用户。            -

 // Connects to your Database 
 mysql_connect("localhost", "dbusername", "dbpassword") or die(mysql_error()); 
 mysql_select_db("mydatabase") or die(mysql_error()); 

//We only run this code if the user has just clicked a voting link
 if ( $mode=="vote") 
 { 

 //If the user has already voted on the particular thing, we do not allow them to vote     again    
    //$cookie = "Mysite$id"; 
if(isset($_COOKIE[$cookie])) 
    { 
    Echo "Sorry You have already ranked that site <p>"; 
    } 

 //Otherwise, we set a cooking telling us they have now voted 
else 
    { 
    $month = 2592000 + time(); 
    setcookie('Mysite'.$id, 'Voted', $month); 

     //Then we update the voting information by adding 1 to the total votes     and adding their vote (1,2,3,etc) to the total rating 

 mysql_query ("UPDATE userads SET total = total+$voted, votes = votes+1 WHERE id =     $id"); 

    } 
 } 
  if ( $mode2=="vote") 
 { 

 //If the user has already voted on the particular thing, we do not allow them to vote     again    
    //$cookie = "Mysite$id"; 
if(isset($_COOKIE[$cookie])) 
    { 
    Echo "Sorry You have already ranked that site <p>"; 
    } 

 //Otherwise, we set a cooking telling us they have now voted 
else 
    { 
    $month = 2592000 + time(); 
    setcookie('Mysite'.$id, 'Voted', $month); 

     //Then we update the voting information by adding 1 to the total votes     and adding their vote (1,2,3,etc) to the total rating 

 mysql_query ("UPDATE userads SET total = total+$voted, nvotes = nvotes+1 WHERE id =     $id"); 

    } 
 }  

 //Puts SQL Data into an array
 $data = mysql_query("SELECT * FROM userads WHERE id = $id ") or die(mysql_error()); 

 //Now we loop through all the data 
 while($ratings = mysql_fetch_array( $data )) 

?>
<link href="style.css" type="text/css" rel="stylesheet" />
 { 
<?php
echo '<div id="voting_14" class="voting voting_template_votess-up-down">';
echo "<strong class='positive_votes'>";
$current = $ratings[votes];
echo "<span>+" . round($current,0) . "</span>";
echo "<a href=".$_SERVER['PHP_SELF']."?mode=vote&voted=1&id=".$ratings[id].">       <input class='vote_positive' type='submit'></a>";
echo '</strong>';

echo "<strong class='negative_votes'>";
$current2 = $ratings[nvotes]; 
echo "<a href=".$_SERVER['PHP_SELF']."?mode2=vote&voted=2&id=".$ratings[id].">      <input class='vote_negative' type='submit'></a>";
echo "<span>-". round($current2,0) ."</span>";
echo '</strong>';

echo '</div>';

 } 
 ---the end 

我有sql表userads:id,name,username,total,votes,nvotes。

5 个答案:

答案 0 :(得分:2)

将您的代码更正为以下内容,

setcookie('Mysite'.$id, 'Voted', $month); // ERROR 1

 while($ratings = mysql_fetch_array( $data )) 
{  // ERROR 2
?>

答案 1 :(得分:1)

我将您的代码复制粘贴到文件中并运行:

php -l your_script.php

收率:

Parse error: syntax error, unexpected '}' in your_script.php on line 78

因此,最后一个括号}导致解析错误。或者您没有发布匹配的if / while /等。在你的帖子中,问题出在其他地方。

答案 2 :(得分:0)

您遇到语法错误。可能您的配置不会显示错误,而且会出现空白屏幕。

答案 3 :(得分:0)

这里缺少引号:

  setcookie(Mysite.$id, Voted, $month); 

应该是:

  setcookie('Mysite'.$id, 'Voted', $month); 

答案 4 :(得分:0)

您的查询显然有问题。您可以通过简单的方法检查SQL查询:

$sql = "SELECT * FROM userads WHERE id = $id ";
echo $sql;

我的第一个猜测是,$id未正确设置。