日期值不正确:第 1 行 'birthday' 列的 ''
Incorrect date value: '' for column 'birthday' at row 1
我是 PHP 的新手,我正在尝试创建一个注册表单,我正在获取
"Incorrect date value: '' for column 'birthday' at row 1
错误。起初我以为这是查询,但我修复了它,但我仍然收到错误,它只是一个不同的列。找遍了,还是没有,求助
我的add.php代码
<?=
$first_name = ( !empty($_GET['f-name']) ) ? $_GET['f-name']: "";
$last_name = ( !empty($_GET['l-name']) ) ? $_GET['l-name']: "";
$email = ( !empty($_GET['email']) ) ? $_GET['email']: "";
$password = ( !empty($_GET['psw']) ) ? $_GET['psw']: "";
$birthday = ( !empty($_GET['age']) ) ? $_GET['age']: "";
$phone = ( !empty($_GET['phone']) ) ? $_GET['phone']: "";
$ministry = ( !empty($_GET['ministry']) ) ? $_GET['ministry']: "";
$query = "INSERT INTO `member` (`first_name`, `last_name`, `email`, `password`, `birthday`, `phone`, `ministry`) VALUES ('$first_name', '$last_name', '$email', '$password', '$birthday', '$phone', '$ministry')";
$hostname = 'localhost';
$db_name = 'catacumba';
$username = 'root';
$password = 'mysql';
try{
$db = new mysqli($hostname, $username, $password, $db_name);
if ($db->query($query) === TRUE) {
echo "Record Created";
} else {
echo "Error Creating record: " . $db->error;
}
//close the connection to DB
$db->close();
}catch(Exception $e)
{
$error_message = $e->getMessage();
echo "<p>Error message: $error_message </p>";
}
?>
我的create_account.php表格
<form class="modal-content" action="Add.php" method="post">
<div class="container">
<button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">X</button>
<h1>Create Account</h1>
<p>Please fill in this form to create an account.</p>
<hr>
<div class="parent">
<div class="child">
<div class="parent2">
<div class="child2">
<label for="f-name"><b>First Name</b></label>
<input type="text" placeholder="First Name" name="f-name" required>
</div>
<div class="child2">
<label for="l-name"><b>Last Name</b></label>
<input type="text" placeholder="Last Name" name="l-name" required>
</div>
</div>
<label for="email"><b>Email</b></label>
<input type="text" placeholder="Enter Email" name="email" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
</div>
<div class="child">
<label for="phone"><b>Phone</b></label>
<input type="tel" placeholder="Phone" name="phone" required>
<label for="ministry"><b>Ministry</b></label>
<input type="text" placeholder="Ministry" name="ministry" required>
<label for="age"><b>Birthday</b></label>
<input type="date" placeholder="Birthday" name="age" required>
</div>
</div>
<label>
<input type="checkbox" checked="checked" name="remember" style="margin-bottom:15px"> Remember me
</label>
<p>By creating an account you agree to our <a href="#" style="color:dodgerblue">Terms & Privacy</a>.</p>
<div class="clearfix" id="createbtn">
<button type="submit" class="signupbtn">Sign Up</button>
</div>
</div>
</form>
列值不正确是一个MySQL错误与您为[=10=选择的列数据类型相关].
如果您插入的 birthday
值与 MySQL date
数据类型 2021-02-22 17:03:24
有任何不同,您将收到此列类型错误。
确保您要插入的生日的格式为 YYYY-MM-DD HH:MM:SS
。
至于使用mysqli
,不要。请改用 PDO。
我是 PHP 的新手,我正在尝试创建一个注册表单,我正在获取
"Incorrect date value: '' for column 'birthday' at row 1
错误。起初我以为这是查询,但我修复了它,但我仍然收到错误,它只是一个不同的列。找遍了,还是没有,求助
我的add.php代码
<?=
$first_name = ( !empty($_GET['f-name']) ) ? $_GET['f-name']: "";
$last_name = ( !empty($_GET['l-name']) ) ? $_GET['l-name']: "";
$email = ( !empty($_GET['email']) ) ? $_GET['email']: "";
$password = ( !empty($_GET['psw']) ) ? $_GET['psw']: "";
$birthday = ( !empty($_GET['age']) ) ? $_GET['age']: "";
$phone = ( !empty($_GET['phone']) ) ? $_GET['phone']: "";
$ministry = ( !empty($_GET['ministry']) ) ? $_GET['ministry']: "";
$query = "INSERT INTO `member` (`first_name`, `last_name`, `email`, `password`, `birthday`, `phone`, `ministry`) VALUES ('$first_name', '$last_name', '$email', '$password', '$birthday', '$phone', '$ministry')";
$hostname = 'localhost';
$db_name = 'catacumba';
$username = 'root';
$password = 'mysql';
try{
$db = new mysqli($hostname, $username, $password, $db_name);
if ($db->query($query) === TRUE) {
echo "Record Created";
} else {
echo "Error Creating record: " . $db->error;
}
//close the connection to DB
$db->close();
}catch(Exception $e)
{
$error_message = $e->getMessage();
echo "<p>Error message: $error_message </p>";
}
?>
我的create_account.php表格
<form class="modal-content" action="Add.php" method="post">
<div class="container">
<button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">X</button>
<h1>Create Account</h1>
<p>Please fill in this form to create an account.</p>
<hr>
<div class="parent">
<div class="child">
<div class="parent2">
<div class="child2">
<label for="f-name"><b>First Name</b></label>
<input type="text" placeholder="First Name" name="f-name" required>
</div>
<div class="child2">
<label for="l-name"><b>Last Name</b></label>
<input type="text" placeholder="Last Name" name="l-name" required>
</div>
</div>
<label for="email"><b>Email</b></label>
<input type="text" placeholder="Enter Email" name="email" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
</div>
<div class="child">
<label for="phone"><b>Phone</b></label>
<input type="tel" placeholder="Phone" name="phone" required>
<label for="ministry"><b>Ministry</b></label>
<input type="text" placeholder="Ministry" name="ministry" required>
<label for="age"><b>Birthday</b></label>
<input type="date" placeholder="Birthday" name="age" required>
</div>
</div>
<label>
<input type="checkbox" checked="checked" name="remember" style="margin-bottom:15px"> Remember me
</label>
<p>By creating an account you agree to our <a href="#" style="color:dodgerblue">Terms & Privacy</a>.</p>
<div class="clearfix" id="createbtn">
<button type="submit" class="signupbtn">Sign Up</button>
</div>
</div>
</form>
列值不正确是一个MySQL错误与您为[=10=选择的列数据类型相关].
如果您插入的 birthday
值与 MySQL date
数据类型 2021-02-22 17:03:24
有任何不同,您将收到此列类型错误。
确保您要插入的生日的格式为 YYYY-MM-DD HH:MM:SS
。
至于使用mysqli
,不要。请改用 PDO。