- Code: Select all
<tr>
<td><input type="checkbox" name="check[]" value="one"></td>
<td><input type="checkbox" name="check[]" value="two"></td>
<td><input type="checkbox" name="check[]" value="three"></td>
<td><input type="checkbox" name="check[]" value="four"></td>
</tr>
This gets passed to the php processor as an array just fine. What I am trying to do, is find out if the userid is already in the database table, and if it is, then to go thru the array and update the fields for each filed checked. If the checkbox is null, then enter a "no", if its checked, then enter a "yes".
However, if the userid is not in that table, then I want it to insert the userid and the apropriate fields into the table. The names of the check boxes correlate with the names of the fileds in the table. Here is the code so far..
- Code: Select all
session_start();
include 'config.php';
$userid = $_SESSION['userid'];
if(!empty($_POST['check'])) {
$query1 = "SELECT `userid` FROM `interests` WHERE `userid`= '$userid '";
$result = mysql_query($query1);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
foreach($_POST['check'] as $check) {
if($check != "yes") {
echo 'CHECK = NULL </br>';
$change="no";
} else {
echo 'CHECK = '.$check. '</br>';
$change="yes";
}
$query = "UPDATE interests SET $choice=$change WHERE userid='$userid'";
mysql_query($query);
}
}
}
echo 'Your interests have been updated into the database, and those files will now</br>';
echo 'begin showing up in the files area on your files sections.';
It is not working yet. Can anyone see where I might need to be heading or doing something differently?
Thanks