Jump to content

unexpected T_STRING on line 51


Dville

Recommended Posts

the code is

[code]$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']);
}[/code]


I just don't get what's breaking this script. line 51 is the mysql_query in the else statement
Link to comment
https://forums.phpfreaks.com/topic/14994-unexpected-t_string-on-line-51/
Share on other sites

sweet, now that works
now the code looks like

[code=php:0]$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']);
}[/code]

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?
[quote].. 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?[/quote]

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:

[code]
$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[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.