Phpfr3ak Posted February 5, 2012 Share Posted February 5, 2012 Its the $query = "INSERT INTO hitlist hit_id = ($addIDs_str), player_id = '$playerID'"; Thats the issue, my codes below i cannot figure out how to insert the results, any help would be appreciated Thanks if (isset($_POST["submit"]) && $_POST["submit"] == "Recall Selected Informants") { //Force POST values to be INTs $addIDs_ary = array_map('intval', $_POST['chkInv']); //Remove any 'false' value $addIDs_ary = array_filter($addIDs_ary); //Check that there was at least one valid value if(count($addIDs_ary)) { //Create comma separated string of the IDs $addIDs_str = implode(',', $addIDs_ary); //Create and run one query to perform all the adds (of the user) $query = "INSERT INTO hitlist hit_id = ($addIDs_str), player_id = '$playerID'"; $sql = "UPDATE players SET Informants = Informants - 1 WHERE id = '$playerID'"; mysql_query($sql) or die(mysql_error()); if(mysql_query($query)) { $selectedCount = count($addIDs_ary); $adddCount = mysql_affected_rows(); echo "{$adddCount} of {$selectedCount} Investigated player(s) were successfully Removed."; if($adddCount != $selectedCount) { echo " You do not have rights to the others."; } }else{ echo "There was a problem running the query.<br>" . mysql_error(); } }else{ echo "Invalid ID data passed."; } } Quote Link to comment https://forums.phpfreaks.com/topic/256435-issue-running-query/ Share on other sites More sharing options...
AyKay47 Posted February 5, 2012 Share Posted February 5, 2012 http://dev.mysql.com/doc/refman/5.1/en/insert.html Quote Link to comment https://forums.phpfreaks.com/topic/256435-issue-running-query/#findComment-1314657 Share on other sites More sharing options...
trq Posted February 5, 2012 Share Posted February 5, 2012 What? You haven't told us what the issue is. Quote Link to comment https://forums.phpfreaks.com/topic/256435-issue-running-query/#findComment-1314672 Share on other sites More sharing options...
Phpfr3ak Posted February 5, 2012 Author Share Posted February 5, 2012 Sorry completely over looked that There was a problem running the query. 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 'hit_id = (2,3), player_id = '17'' at line 2 is the error msg im getting really unsure as to why Quote Link to comment https://forums.phpfreaks.com/topic/256435-issue-running-query/#findComment-1314791 Share on other sites More sharing options...
PFMaBiSmAd Posted February 5, 2012 Share Posted February 5, 2012 Did you check the mysql manual for the correct syntax for what you are doing, like the error message suggests? The following is the insert syntax definition for the form of the insert query you are using, with the parts you are trying to use highlighted in red - INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [iGNORE] [INTO] tbl_name SET col_name={expr | DEFAULT}, ... [ ON DUPLICATE KEY UPDATE col_name=expr [, col_name=expr] ... ] It's not possible to write code or a query for your data, until you learn the correct way to write the code or a query at all. Programming is an exact science. Leaving out one keyword changes the meaning of what you are doing and makes it so that the programming language or sql language doesn't know what you are telling it to do. Quote Link to comment https://forums.phpfreaks.com/topic/256435-issue-running-query/#findComment-1314793 Share on other sites More sharing options...
Phpfr3ak Posted February 5, 2012 Author Share Posted February 5, 2012 I did try this, but it only works for one user and not the rest, sorry i probably am missing something easy here but i just cannot get my head around it $query = "INSERT INTO hitlist(hit_id,player_id) VALUES ('$addIDs_str','$playerID')"; $sql = "UPDATE players SET Informants = Informants - 1 WHERE id = '$playerID'"; mysql_query($sql) or die(mysql_error()); if(mysql_query($query)) { Quote Link to comment https://forums.phpfreaks.com/topic/256435-issue-running-query/#findComment-1314797 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.