With the below code it only inserts the last checkbox selected into the db, however if I spit the code out it shows all inserts strings generated. Any suggestions?
HTML Code:
<input name="state_rep[1]" type="checkbox" title="Alabama">AL
<input name="state_rep[2]" type="checkbox" title="Alaska">AK
<input name="state_rep[3]" type="checkbox" title="Aamerican Samoa">AS
<input name="state_rep[4]" type="checkbox" title="Arizona">AZ
<input name="state_rep[5]" type="checkbox" title="Arkansas">AR
<input name="state_rep[6]" type="checkbox" title="California">CA
<input name="state_rep[7]" type="checkbox" title="Colorado">CO
PHP Code:
<?
function update_person_detail_state_rep() {
global $defaults, $_POST;
foreach($_POST['state_rep'] as $key => $value) {
echo "insert into person_state_rep (person_id, state_id) values ('".$_POST["id"]."', '".$key."')";
}
if (mysql_connect($defaults["db_server"], $defaults["db_username"], $defaults["db_password"])) {
if (mysql_select_db($defaults["db_database"])) {
if (mysql_query($query)) {
}
else {
die ("<h3>SQL Error #".mysql_errno()."</h3>\n<h4>".mysql_error()."</h4>\n<h4>Line ".__LINE__." in ".__FILE__."</h4>\n");
}
}
else {
die ("<h3>SQL Error #".mysql_errno()."</h3>\n<h4>".mysql_error()."</h4>\n<h4>Line ".__LINE__." in ".__FILE__."</h4>\n");
}
}
else {
die ("<h3>SQL Error #".mysql_errno()."</h3>\n<h4>".mysql_error()."</h4>\n<h4>Line ".__LINE__." in ".__FILE__."</h4>\n");
}
}
?>
|