我試圖從下拉列表中插入數據到我的數據庫,但是我遇到了一個錯誤,請幫忙。 DOB在我的數據庫中設置爲日期格式。DOB mysql插入
PS。然而,它插入到我的年月天罰款沒有任何問題。
在此先感謝,併爲貧困英語技能對不起=(
下面是我的PHP代碼
<?php
require '../ppuyakul/php/db_conn.php';
error_reporting(0);
$message = '';
$year = $_POST['year'];
$month = $_POST['month'];
$date = $_POST['date'];
$DOB = date("Y-m-d", mktime(0,0,0,$month, $day, $year));
if(!empty($_POST['email']) && !empty($_POST['password']) && !empty($_POST['fullname']) && !empty($_POST['username']) && !empty($_POST['password_confirmation']) && !empty($_POST['gender']) && !empty($_POST['country']) && !empty($_POST['state']) && !empty($_POST['city']) && !empty($_POST['day']) && !empty($_POST['month']) && !empty($_POST['year'])):
// Enter the new user in the database
$sql = "INSERT INTO assignment2 (fullname,username, email, password, passwordcon, gender, country, state, city, day, month, year, DOB) VALUES (:fullname, :username, :email, :password, :password_confirmation, :gender, :country, :state, :city, :day, :month, :year, DOB)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':fullname', $_POST['fullname']);
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':email', $_POST['email']);
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
$stmt->bindParam(':password_confirmation', password_hash($_POST['password_confirmation'], PASSWORD_BCRYPT));
$stmt->bindParam(':gender', $_POST['gender']);
$stmt->bindParam(':country', $_POST['country']);
$stmt->bindParam(':state', $_POST['state']);
$stmt->bindParam(':city', $_POST['city']);
$stmt->bindParam(':day', $_POST['day']);
$stmt->bindParam(':month', $_POST['month']);
$stmt->bindParam(':year', $_POST['year']);
$stmt->bindParam(':DOB', $_POST['year'], $_POST['month'], $_POST['day']);
if($stmt->execute()):
$message = 'Successfully created new user';
else:
$message = 'Sorry there must have been an issue creating your account';
endif;
endif;
?>
這裏是我的HTML
<div>
<p style="display: inline; margin-right: 1%"><span style="font-weight: bold;">DATE OF BIRTH :</span></p>
<select class="formInputDate" name="day" value="" id="day"></select>
<select class="formInputDate" name="month" id="month">
<option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
<option value="4">Apr</option>
<option value="5">May</option>
<option value="6">Jun</option>
<option value="7">Jul</option>
<option value="8">Aug</option>
<option value="9">Sep</option>
<option value="10">oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
<select class="formInputDate" name="year" value="" id="year">
</select>
</div>
1.什麼是錯誤? 2.你期望從'bindParam(':DOB',$ _POST ['year'],$ _POST ['month'],$ _POST ['day'])''? –
這看起來不正確......':月份,:年份,出生日期)'缺少冒號? –
感謝您的回覆,我很新的PHP,哪個命令打印出來的錯誤,因爲現在它只是不插入數據到數據庫,但沒有顯示任何東西, –