Jump to content


Photo

unexpected T_STRING on line 51


  • Please log in to reply
9 replies to this topic

#1 Dville

Dville
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 19 July 2006 - 12:38 AM

the code is

$aprid = $_GET['appid'];


if (mysql_query("select * from articles left join votes on articles.id = votes.id WHERE username= '$username' AND articleid= '$id'"))
{
echo "You have already voted on this article before";
}

else {
mysql_query(INSERT INTO votes(username, articleid) VALUES('" .$username. "','" .$aprid. "'));
header('Location: ' . $_SERVER['HTTP_REFERER']);
}


I just don't get what's breaking this script. line 51 is the mysql_query in the else statement

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 19 July 2006 - 12:41 AM

You are missing a double quote after mysql_query( and before INSERT INTO

mysql_query("INSERT IN

#3 Dville

Dville
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 19 July 2006 - 12:46 AM

then i get the error

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\www\digg\vote.php on line 53

#4 treilad

treilad
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 19 July 2006 - 12:49 AM

We'd have to see vote.php.

#5 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 19 July 2006 - 12:51 AM

You are probably missing one at the end of that same statement then...

mysql_query("INSERT INTO ... " .$aprid. "')");

#6 Dville

Dville
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 19 July 2006 - 01:07 AM

sweet, now that works
now the code looks like

$aprid = $_GET['appid'];


if (mysql_query("SELECT * FROM votes WHERE username = '$username' AND articleid = '$aprid'"))
{
echo "You have already voted on this article before.";
}

else {
mysql_query("INSERT INTO votes(username, articleid) VALUES('" .$username. "','" .$aprid. "')");
header('Location: ' . $_SERVER['HTTP_REFERER']);
}

i only have one thing in my votes table, id of 1, username of admin, and articleid of 84

so unless my username and aprid variable is admin and 84 respectively, the if statement would return null, and go to the else statement. correct?

but why when I do this, no mater what the aprid variable is, 84, 4, 70, it always tells me i've already voted on this article, and doesnt go to the else statement
and thoughts?

#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 19 July 2006 - 01:11 AM

.. but why when I do this, no mater what the aprid variable is, 84, 4, 70, it always tells me i've already voted on this article, and doesnt go to the else statement
and thoughts?


Because what you are testing is whether the query is valid (which it is), not whether it returns a result.

This may be more helpful:

$query = "SELECT * FROM votes WHERE username = '$username' AND articleid = '$aprid'";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
$count = mysql_num_rows($result);
if ($count==1) {
// you have already voted

... now use the logical balance of your loop

Legend has it that reading the manual never killed anyone.
My site

#8 Dville

Dville
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 19 July 2006 - 01:16 AM

so is there any way i can do this?

I was told from here
http://www.phpfreaks....html#msg396773

i could, since it's returning 0 if nothing is there

EDIT - k, lemme test that

#9 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 19 July 2006 - 01:18 AM

Sorry, I edited my post to include the solution ... just took a 2-minute break :)
Legend has it that reading the manual never killed anyone.
My site

#10 Dville

Dville
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 19 July 2006 - 01:21 AM

kick freaking ass, man i've been stuck on this restricting votes to one per article for over a week, with the mysql join command driving me INSAAAAANE

now i can breathe normal again. thanks alot




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users