Dville Posted July 19, 2006 Share Posted July 19, 2006 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 More sharing options...
hitman6003 Posted July 19, 2006 Share Posted July 19, 2006 You are missing a double quote after mysql_query( and before INSERT INTOmysql_query("INSERT IN Link to comment https://forums.phpfreaks.com/topic/14994-unexpected-t_string-on-line-51/#findComment-60261 Share on other sites More sharing options...
Dville Posted July 19, 2006 Author Share Posted July 19, 2006 then i get the errorParse 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 Link to comment https://forums.phpfreaks.com/topic/14994-unexpected-t_string-on-line-51/#findComment-60265 Share on other sites More sharing options...
treilad Posted July 19, 2006 Share Posted July 19, 2006 We'd have to see vote.php. Link to comment https://forums.phpfreaks.com/topic/14994-unexpected-t_string-on-line-51/#findComment-60266 Share on other sites More sharing options...
hitman6003 Posted July 19, 2006 Share Posted July 19, 2006 You are probably missing one at the end of that same statement then...mysql_query("INSERT INTO ... " .$aprid. "')"); Link to comment https://forums.phpfreaks.com/topic/14994-unexpected-t_string-on-line-51/#findComment-60267 Share on other sites More sharing options...
Dville Posted July 19, 2006 Author Share Posted July 19, 2006 sweet, now that worksnow 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 84so 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 statementand thoughts? Link to comment https://forums.phpfreaks.com/topic/14994-unexpected-t_string-on-line-51/#findComment-60274 Share on other sites More sharing options...
AndyB Posted July 19, 2006 Share Posted July 19, 2006 [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 statementand 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 https://forums.phpfreaks.com/topic/14994-unexpected-t_string-on-line-51/#findComment-60278 Share on other sites More sharing options...
Dville Posted July 19, 2006 Author Share Posted July 19, 2006 so is there any way i can do this?I was told from herehttp://www.phpfreaks.com/forums/index.php/topic,100521.msg396773.html#msg396773i could, since it's returning 0 if nothing is thereEDIT - k, lemme test that Link to comment https://forums.phpfreaks.com/topic/14994-unexpected-t_string-on-line-51/#findComment-60279 Share on other sites More sharing options...
AndyB Posted July 19, 2006 Share Posted July 19, 2006 Sorry, I edited my post to include the solution ... just took a 2-minute break :) Link to comment https://forums.phpfreaks.com/topic/14994-unexpected-t_string-on-line-51/#findComment-60281 Share on other sites More sharing options...
Dville Posted July 19, 2006 Author Share Posted July 19, 2006 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 INSAAAAANEnow i can breathe normal again. thanks alot Link to comment https://forums.phpfreaks.com/topic/14994-unexpected-t_string-on-line-51/#findComment-60283 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.