php脚本中出现意外的$ end?

时间:2011-07-14 04:59:05

标签: php

我有一些对我来说很好的代码,但我一直收到以下错误:

  

“解析错误:语法错误,意外$结尾   第21行/home/txclanco/public_html/hotmuze/addSong.php“

这是一个脚本,它接受来自表单的输入,检查重复项,如果有重复,它将不会创建一个新行,而只是添加1到'rating'行,其中songname是歌曲类型如果没有重复,脚本会将数据添加为新行。数据类型是:

  • id = A_I / int
  • songname = varchar
  • artist = varchar
  • rating = int

脚本如下,mysql数据消失:

<?
  mysql_connect("localhost", "***", "***") or die(mysql_error());
  mysql_select_db("***") or die(mysql_error());
  $songname = $_POST['songname'];
  $artist = $_POST['by'];
  $ratenum = 1; 
  $chkquery = "SELECT * FROM hotmuze WHERE songname='$songname'";
  $plusOneQuery = "SELECT * FROM hotmuze WHERE songname='$songname'";
  $updateQuery = "UPDATE hotmuze SET rating='$rating2' WHERE songname='$songname'";
  $checkdata = mysql_query($chkquery);
  $checkrows = mysql_num_rows($checkdata); 

  if($checkrows==0) 
  {
      $insquery = "INSERT INTO hotmuze (id, songname, artist, rating) VALUES('', '$songname', '$artist', '$ratenum'";
      $insdata = mysql_query($insquery); 
  }

  if($checkrows!=0) 
  { 
    $plusData = mysql_query($plusOneQuery);
  }

  if(mysql_num_rows($plusData)!=0) 
  {
    $result = mysql_fetch_assoc($plusData);
    $rating = $result['ratng'];
    $rating2 = $rating + 1;
    mysql_query($updateQuery); 
    echo "Data Inserted";
  } 
?>

第21行:

if($checkrows!=0) 
{
  // The brace is on line 21
  $plusData = mysql_query($plusOneQuery);
}

任何想法脚本可能出错?我知道意外的$ end错误通常意味着有一个支架不合适,但这次,它没关系?

3 个答案:

答案 0 :(得分:1)

更改此

 $insquery = "INSERT INTO hotmuze (id, songname, artist, rating) VALUES('', '$songname', '$artist', '$ratenum'";

$insquery = "INSERT INTO hotmuze (id, songname, artist, rating) VALUES('', '$songname', '$artist', '$ratenum')";

你错过了最后的)

答案 1 :(得分:0)

VALUES打开和关闭'()'需要

    $insquery = "INSERT INTO hotmuze (id, songname, artist, rating) 
VALUES('', '$songname', '$artist', '$ratenum')";

答案 2 :(得分:0)

根据右括号数计算左括号的数量。

$ insquery =“INSERT INTO hotmuze(id,songname,artist,rating)VALUES('','$ songname','$ artist','$ ratenum')”;