Created
July 19, 2014 21:14
-
-
Save davemorrissey/cfb630aec926a0530ac0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$host="localhost"; | |
$username="******"; | |
$password="*******"; | |
$db_name="signuplist"; | |
$tbl_name="signupbydate"; | |
$myusername=$_SESSION['logname']; | |
?> | |
<html> | |
<head> | |
<title>Checkbox</title> | |
<head> | |
<title>HTML Checkbox</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 | |
$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; } | |
} | |
// MySQL statement. Don't forget to strip to avoid sql injection | |
$sql1="UPDATE $tbl_name | |
SET playdate1=$values[playdate1], playdate2=$values[playdate2], playdate3=$values[playdate3], playdate4=$values[playdate4], playdate5=$values[playdate5] | |
WHERE username='$myusername'"; | |
echo $sql1; | |
} // End of, if statement from the button check | |
?> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment