This first part seems excessively long and I would appreciate any tips to shorten it. But the next part is even more tedious, and I'm wondering how I can loop through the block of code for all 40 checkboxes. The word 'Albanian' is the one I'm hoping to substitute for some sort of variable corresponding to each checkbox value...
Code: Select all
if (isset($_POST['Albanian'])) { //first see if lcheckbox was checked
//if so, then try to insert values as if it is the first time being entered
$query_insert1= "INSERT INTO prod_lang_lookup (Product_ID, Language_ID, ActiveLang)
VALUES (".$pID.", (SELECT Language_ID FROM languages WHERE LanguageName = 'Albanian'), 1)";
$result1 = mysql_query($query_insert1,$myConn);
//if the data for that product and language is already in the table, then update active to 1
if (!$result1) {
$query_activate1= "UPDATE prod_lang_lookup SET ActiveLang = 1 WHERE Product_ID = ".$pID." AND Language_ID = (SELECT Language_ID FROM languages WHERE LanguageName ='Albanian')";
$result1 = mysql_query($query_activate1,$myConn);
}
//otherwise, if checkbox is not checked, update active to 0
} else {
// first try insert to 0
$query_insert1= "INSERT INTO prod_lang_lookup (Product_ID, Language_ID, ActiveLang)
VALUES (".$pID.", (SELECT Language_ID FROM languages WHERE LanguageName = 'Albanian'), 0)";
$result1 = mysql_query($query_insert1,$myConn);
// if data already exists, then we do an update to 0
if (!$result1) {
$query_activate1= "UPDATE prod_lang_lookup SET ActiveLang = 0 WHERE Product_ID = ".$pID." AND Language_ID = (SELECT Language_ID FROM languages WHERE LanguageName ='Albanian')";
$result1 = mysql_query($query_activate1,$myConn);
}
}