i’m quite new with php. i think this is quite straight forward but i’m confused.
i have a form which asks users for a date of their choice, the format they enter is dd/mm/yyyy
the linked mysql database is formatted yyyy/mm/dd, from what i understand you can’t change this.
i’m just trying to figure out where i can change the format of the date. would it be in the sql line that sends the information?
i found this unrelated answer:
<?php
$date = date("Y-m-d");
mysql_query("INSERT INTO date_table VALUES ('$name', '$date')", $db_connection);
?>
but i can’t get this to work…
here are some snippets of the code i currently have:
// Check for night attending:
if (empty($_POST['night_attending'])) {
$errors[] = 'You forgot to enter the night you want to attend.';
} else {
$na = mysqli_real_escape_string($dbc, trim($_POST['night_attending']));
}
……………………………….
// Make the query:
$q = "INSERT INTO guests (first_name, last_name, email, night_attending) VALUES ('$fn', '$ln', '$e', '$na')";
$r = @mysqli_query ($dbc, $q); // Run the query.
if ($r) { // If it ran OK.
……………………………….
<p>Night Attending: <input type="text"id="datepicker" name="night_attending" size="10" value="<?php if (isset($_POST['night_attending'])) echo $_POST['night_attending']; ?>" /></p>
thanks for your time guys.
alastair
Update: (Based On Comments)
To get the date value from your form, you can do this:
Where it is assumed that:
POSTmethod in your<form>tag or change accordingly.You need to use
strtotime: