Karan K
Karan K

Reputation: 715

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:

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?

Upvotes: 0

Views: 124

Answers (3)

Mob
Mob

Reputation: 11106

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')";

Upvotes: 0

jeni
jeni

Reputation: 440

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

Upvotes: 1

K6t
K6t

Reputation: 1845

VALUES open and close '()' is need

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

Upvotes: 0

Related Questions