Okay so not long ago I requested this

How can I grab and store multiple $_POST Variables in a for each loop?

And also the response was perfect, also it labored for placing the values in to the database all right. However, Now i am returning to this project and I wish to UPDATE just one area within the database, particularly the publish test area for your particular user, utilizing the same or similar method. Wouldso would this be possible?

Presently I've something like this.

$SGUID = the Unique User ID
$SGpost = the field i want to update
$SGQID = question ID

Clearly, this doesn't work.. and my code is very sloppy when i attempted to exchange and edit this on the way. Any ideas?

foreach ($_POST as $p => $v)
{

 if (preg_match("/^Q\d+$/",$p)) {   //$_POST variables with Q1, Q2, Q3, etc etc

$query_3 = mysql_query("UPDATE SGresults SET SGpost = '$p', SGpostCheck = 1 WHERE SGUID = '$SGUID' AND SGQID = '$p'") or die('Error: '.mysql_error ());
    $SGQID++;

}
}
}   

After I echo out $p I recieve the next Q11 Q21 Q31 Q44 Q54 Q63 Q73 Q83 Q93 Q103 Q111 Q122 Q131 Q142 Q153 Q163 Q17

That is things i want, except with no Q, and merely the 2nd value. So for instance whether it was 'Q163' Among the finest to place the '3' part into SGpost In which the database is 'Q16'.

Many thanks again! Any help could be greatly appreciated!

EDIT:: Viewed my code again and transformed some values around...The next Works, and so i think I'll stick to it. Unless of course bad code? Many thanks for the suggestions.

$SGQID= 1;

foreach ($_POST as $i => $v)
  {
    if (preg_match("/^Q\d+$/",$i)) {    //$_POST variables with Q1, Q2, Q3, etc etc
// Here we insert value $v to database
    if ($SGtestType == "Post-test") {

    $query_post = mysql_query("UPDATE SGresults SET SGpost = '$v', SGpostcheck ='1' WHERE SGQID = '$SGQID' AND SGUID = '$SGUID'  ") or die('Error 109: '.mysql_error ());
    $SGQID++;           
    // ^^ increments the question value everytime an insert is made
    //last 2 fields is check for existing value.. or if not exists.. 1 if it does.
    }


Presuming you trust the publish data not to be an xss attack:

    foreach ($_POST as $p => $v)
    {

     if (preg_match("/^Q(\d+)$/",$p, $matches)) {   //$_POST variables with Q1, Q2, Q3, etc etc

$id = (int)$matches[1];

    $query_3 = mysql_query("UPDATE SGresults SET SGpost = '$id', SGpostCheck = 1 WHERE SGUID = '$SGUID' AND SGQID = '$id'") or die('Error: '.mysql_error ());
        $SGQID++;

    }
    }
    }