So I am creating a very simple form wherein I want to add data from an HTML form using PHP into a MySQL database. Unfortunately, the format that the input type="date" tag gives me is this:but what MySQL requires is this:
. I have searched a lot of online sources for solutions but everyone seems to say that the formats cannot be changed. I do not want to change the formats, I just want to be able to add them into the database. Here is the full HTML/PHP script if relevant:
store.html:
<!DOCTYPE html>
<html>
<head>
<title>Progress</title>
</head>
<body>
<form action="store.php" method="get">
Customer Name<input type="text" name="cname"><br>
Purchase order date<input type="date" id="podate"/><br>
<label for="yn">Work started?</label>
<select id="yn" name="yn">
<option value="yes">Yes</option>
<option value="no">No</option>
</select><br>
<label for="ifno">(If above selected is no)Reason for delay?</label>
<select id="ifno" name="ifno">
<option value="nodelay">No delay</option>
<option value="dipl">Delay from DIPL</option>
<option value="customer">Delay from customer</option>
</select><br>
Tentative start date<input type="date" name="tentdate"><br>
<label for="progress">Progress</label>
<select id="progress" name="progress">
<option value="started">Just Started</option>
<option value="almost">Almost Finished</option>
</select><br>
<input type="submit" name="sub" value="Submit">
</form>
</body>
</html>
store.php
<?php
include 'config.php';
$cname=$_GET['cname'];
$podate=$_GET['podate'];
$started=$_GET['yn'];
$reason=$_GET['ifno'];
$tentdate=$_GET['tentdate'];
$progress=$_GET['progress'];
if($cname=="" || $podate==""||$started=="" || $reason==""||$tentdate=""||$progress=""){
$message="All fields must be filled";
echo "<script type='text/javascript'>alert('$message');
window.location.href='store.html';</script>";
}
else{
$sql = "INSERT INTO info (cname, podate, started, reason, tentdate, progress) VALUES ('$cname', '$podate', '$started', '$reason', '$tentdate', '$progress')";
if (mysqli_query($conn, $sql)) {
//echo "New record created successfully";
header('Location: store.html');
} else {
$message="Something went wrong. Please try again.";
echo "<script type='text/javascript'>alert('$message');
window.location.href='store.html';</script>";
}
}
mysqli_close($conn);
?>
My problem here is that the HTML and MySQL formats do not match which disables me from storing it into the database. I also tried to use DATE_FORMAT() in the insert statement but later learned that it can be used for displaying but not inserting.
Thank you.