dementor Posted July 16, 2008 Share Posted July 16, 2008 I decided today to make a script for voting on my site <?php session_start(); include "mysql.php"; include "global_func.php"; global $c; $is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error()); $ir=mysql_fetch_array($is); check_level(); $user=$_POST['userid']; $q=mysql_query("SELECT * FROM votes WHERE userid='$user' AND list='toprpg'",$c); if(mysql_num_rows($q)) { event_add($_POST['userid'],"You voted today already.",$c); } else { event_add($_POST['userid'],"Well done for voting keep it up.",$c); mysql_query("UPDATE users SET crystals=crystals+1 WHERE userid='$user'"); mysql_query("INSERT INTO votes values ('$user','toprpg')",$c); } ?> That is what I come up with and I get the error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Im clueless where that error is comeing from do you ? Quote Link to comment Share on other sites More sharing options...
Guest Anonymous Posted July 16, 2008 Share Posted July 16, 2008 Re: Support Needed mysql_query("INSERT INTO votes values ('$user','toprpg')",$c); ...... mysql_query("INSERT INTO votes (column, column) VALUES('$user, '$toprpg' )",$c); replace "column" to the database structure columns. Quote Link to comment Share on other sites More sharing options...
dementor Posted July 16, 2008 Author Share Posted July 16, 2008 Re: Support Needed Wrong answer mate Quote Link to comment Share on other sites More sharing options...
Spudinski Posted July 16, 2008 Share Posted July 16, 2008 Re: Support Needed For some reason the variable $user is empty, thus the query error. MySQL, in this case, cannot update the column with the null value, so the error occurs. $user=$_POST['userid']; I'm hoping this is not direct input from a user, that is then used in a query desensitized. My guess here is that your meaning for this was to just use the current "userid", if so then use the below. $user = $ir['userid']; If it isn't you intention, first sanitize the input variable, and also check if the POST array contains any value at the key "userid". This can be done by using an debugging function, you can place it near where the input variable is used. var_dump($_POST); Quote Link to comment Share on other sites More sharing options...
Floydian Posted July 16, 2008 Share Posted July 16, 2008 Re: Support Needed lol Spudinski, you're spot on with that. Somehow I doubt that dementor is capable of carrying out your advice as is evidenced by his complete lack of debugging skills. He can't even tell us which query error is in. Good luck with it bro ;) My advice is to study really hard. Quote Link to comment Share on other sites More sharing options...
dementor Posted July 16, 2008 Author Share Posted July 16, 2008 Re: Support Needed The error is not in one of the queries just in the event add Quote Link to comment Share on other sites More sharing options...
dementor Posted July 16, 2008 Author Share Posted July 16, 2008 Re: Support Needed BTW the I already knew that was the problem im asking where I have gone wrong in the code ! Quote Link to comment Share on other sites More sharing options...
Spudinski Posted July 16, 2008 Share Posted July 16, 2008 Re: Support Needed The error is not in one of the queries just in the event add The event_add() function uses a query to insert a record into the database, and you are using the same variable for all the queries. They all *will* output the same error, for the reason I have supplied earlier. I have given you advice on how to solve this problem, now it's time you help yourself. Quote Link to comment Share on other sites More sharing options...
dementor Posted July 16, 2008 Author Share Posted July 16, 2008 Re: Support Needed I think the error is more the code being used to go vote Quote Link to comment Share on other sites More sharing options...
Floydian Posted July 16, 2008 Share Posted July 16, 2008 Re: Support Needed Why do I feel like I'm watching mystery science theater 3000? Quote Link to comment Share on other sites More sharing options...
dementor Posted July 16, 2008 Author Share Posted July 16, 2008 Re: Support Needed How can I put the voting site is not posting the ID hence why it is an error saying nothing was inputted So I need to check my URL from the voting site get what I am saying now ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.