Jump to content

Issue running query


Phpfr3ak

Recommended Posts

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.";
}
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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))
{

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.