开发者

Unexpected $end in php script?

I have this bit of code that looks fine to me, but I keep getting the following error:

"Parse error: syntax error, unexpected $end in /home/txclanco/public_html/hotmuze/addSong.php on line 21"

This is a script that takes in the input from a form, checks for duplicates and if there is a duplicate, it will not make a new row but just add 1 to the 'rating' row where the songname is the song typed in. If there isn't a duplicate, the script will add the data as a new row. The data types are:

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

The script is below with the mysql data blanked out:开发者_运维技巧

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

Line 21 being:

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

Any ideas what could be wrong with the script? I know the Unexpected $end error usually means that there's a brace out of place, but this time, it's fine?


change this

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

to

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

you have missed the ) at end


VALUES open and close '()' is need

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


Count the number of opening brackets you have against the number of closing brackets.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜