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
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?
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.