I have the following code to update sql database depending on checked values. The problem is that I only want to update the values that are checked and leave the other values as is, whereas my current code updates everything as either a zero or one. I have tried many different ways to accomplish this without success. Would also welcome a suggestion as to how to make the 'else' statement concerning empty inpput only appear after Submit is clicked instead of all the time. Very new to writing code, so apologies if the answer is obvious and I am missing it, and thanks for your help!
$host="localhost";
$username="######";
$password="#######";
$db_name="signuplist";
$tbl_name="signupbydate";
$myusername=$_SESSION['logname'];
?>
<head>
<title>Request Date</title>
</head>
<body>
<div style='margin-left:6.0in; margin-top:0.75in'>
<p style='font-weight:bold'>
When would you like to play golf?</p>
<p>Choose the dates you wish to play</p>
<p>Make sure you click 'Update' when you are done</p>
<form name="requesttime" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="checkbox" name="playdate[]" value="playdate1"> September 3, 2014 <br>
<input type="checkbox" name="playdate[]" value="playdate2"> September 6, 2014 <br>
<input type="checkbox" name="playdate[]" value="playdate3"> September 10, 2014 <br>
<input type="checkbox" name="playdate[]" value="playdate4"> September 13, 2014 <br>
<input type="checkbox" name="playdate[]" value="playdate5"> September 17, 2014 <br>
<br>
<input type="submit" value="Update" name="submit">
<?php
$cxn=mysqli_connect($host,$username,$password,$db_name)
or die ("Couldn't Connect to Server");
$chkbox = array('playdate1', 'playdate2', 'playdate3', 'playdate4', 'playdate5');
if(isset($_POST['submit']))
{ $playdate = $_POST['playdate'];
$values = array();
foreach($chkbox as $selection )
{ if(in_array($selection, $playdate))
{ $values [$selection] = 1; }
else
{$values [$selection] = 0; }
}
$sql1="UPDATE $tbl_name
SET playdate1=$values[playdate1], playdate2=$values[playdate2], playdate3=$values[playdate3], playdate4=$values[playdate4], playdate5=$values[playdate5]
WHERE username='$myusername'";
mysqli_query($cxn, $sql1) or die('<br/>Error reading database: '.mysqli_error($cxn));
mysqli_close($cxn);
}
if(empty($_POST['submit'])) { echo "Make a selection"; exit; }
?>