I have a form comprising of a checkbox list. Instead of the values being pre-determined in the code, I would like for the values to be fed in by the end-user. The value content has to be Date and time. Is this something that can be done? If so kindly point out how I can achieve this.
Please find below my html form for clarification:
<html>
<body>
<form method="post" action="chk123.php">
Flights on: <br/>
<input type="checkbox" name="Days[]" value="Daily"> <input type="datetime-local" value="bdaytime"> <br>
<input type="checkbox" name="Days[]" value="Sunday">Sunday<br>
<input type="checkbox" name="Days[]" value="Monday">Monday<br>
<input type="checkbox" name="Days[]" value="Tuesday">Tuesday <br>
<input type="checkbox" name="Days[]" value="Wednesday">Wednesday<br>
<input type="checkbox" name="Days[]" value="Thursday">Thursday <br>
<input type="checkbox" name="Days[]" value="Friday">Friday<br>
<input type="checkbox" name="Days[]" value="Saturday">Saturday <br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
My php code:
<?php
// Make a MySQL Connection
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
$checkBox = implode(', ', $_POST['Days']);
$checkBoxArray = explode(" ", $checkBox);
if(isset($_POST['submit']))
{
$checkBox = implode(' ', $_POST['Days']);
$checkBoxArray = explode(" ", $checkBox);
foreach ($checkBoxArray as $value)
{
$query="INSERT INTO example (orange) VALUES ('" . $value . "')";
mysql_query($query) or die (mysql_error() );
}
echo "<br />Complete";
}
?>