0

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?

4
  • Your current error aside, your $insquery seems to be declared with a bracket missing at the end of the SQL. Commented Jul 14, 2011 at 5:04
  • 2
    You really need mysql_real_escape_string those vars before putting them in the query :-) Commented Jul 14, 2011 at 5:05
  • Your code parses just fine. Did you remove the syntax error when blanking out MySQL credentials? Commented Jul 14, 2011 at 6:09
  • @Johnathan: Thanks! That was one of the few problems, haha. I redid it with a new structure, it works fine :) Thanks! :) @prodigitalson: Will do :D The script is a tester for me only, and I usually apply security measures later :D haha, thanks :) @AlvaroG: Really? lol, doubt that :S Thanks anyways! Solved it :D Commented Jul 14, 2011 at 19:43

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

if you got any errors in query execution lines. check the root of that. you will find error clear. moreover unexpected $end is for any incomplete closing
Thanks, that was one problem, and there were others. I redid the script with a different structure, and it works! :)
0

VALUES open and close '()' is need

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

1 Comment

Thanks, that was one problem, and there were others. I redid the script with a different structure, and it works! :)
0

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

1 Comment

Thanks, I usually use Notepad++ to do it, but eh :P The Web Editor I use is horrible :( That wasn't the only problem somehow! Either way, I redid the whole code in a different structure, and it worked! Thanks anyways! :)c

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.