Forum Moderators: coopster
foreach($_POST as $key => $value){
echo "$key:$value";
}
when I echo the info it gives me the correct output
game1:7 game1id:513
game2:14 game2id:514
I have columns in the database that correspond to the form var fields What my question is is how do I get the info into the database through each iteration in one row?
This is an example I have tried and I know doesn't work
$sql = "INSERT INTO teampicks ($key) VALUES('". $value ."')";
$res = mysql_query($sql);
Any Help would be appreciated
Regards,
Brandon
e.g
$keys = '';
$vals = '';
foreach($_POST as $key => $value){
$keys .= "`" . $key . "` ,";
$vals .= "'" . $values . "' ,";
}
you will get comma at the end of each strong you can remove it with any string built in function of with a IF within the loop.
foreach($_POST as $key => $value){$keystr .= "$key,";
$valstr .= "'" . $value . "' ,";
}
//strip last comma
$keys = substr($keystr, 0, -1);
$vals = substr($valstr, 0, -1);
$sql = "INSERT INTO teampicks ($keys) VALUES($vals)";
$res = mysql_query($sql);
Regards,
Brandon