This works for me but it adds the datetime in mysql as 1970 01 01 00:00 00
include("mysql_connect.php");
$phpdate = strtotime( $mysqldate );
$mysqldate = date( 'Y-m-d H:i:s', $phpdate );
//check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "INSERT INTO people (username, email, sign_up_date) VALUES ('$_POST[username]','$_POST[usermail]', '" . $mysqldate . "' )";
if (!mysqli_query($mysqli,$sql)) {
die('Error: ' . mysqli_error($mysqli));
}
echo "1 record added";
mysqli_close($mysqli);
Here's my html form:
<section class="loginform tmr">
<form name="login" action="regi.php" method="post" accept-charset="utf-8">
<label for="username">Username: </label><br />
<input type="username" name="username" placeholder="Handle" required><br />
<input type="hidden" name="sign_up_date" value="<?php echo $_POST['sign_up_date'] ?>">
<label for="usermail">Email: </label><br />
<input type="email" name="usermail" placeholder="yourname@email.com" required><br />
<label for="password">Password: </label><br />
<input type="password" name="password" placeholder="password" required><br />
<input type="submit" value="Login">
</form>
</section>
I'm using a hidden input and requesting the post value.
I tried using timesteamp()
and date()
sign_up_date type in mysql is datetime..
should i use something like this?
$insertdate = date('Y-m-d', strtotime($_POST['Date']));
Additionally, I have a field called account_permissions enum('a', 'b', 'c') and I'm wondering how I insert that into my form (should i use another hidden input)... I need it to default to 'a' all the time.
Any help would be greatly appreciated. Thank you.