我的PHP表單不會發布到數據庫中。我很瞭解php和mysql連接,但我很難理解這一點。當我點擊提交表單時,它不會迴應我(用戶)輸入的值。日期顯示爲1969-12-31,而不是用戶提交的日期。如果任何人都可以提供幫助,那會很棒。我的代碼如下PHP表單不會發布到我的數據庫中
形式的代碼是:
<form method="POST" action="add_event.php" id="create_event">
<label for="event_name">Event Name:</label>
<input type="text" id="event_name"><br />
<label for="date">Date:</label>
<input class="datepicker" type="date" id="date"><br />
<label for="zip_code">Zip Code:</label>
<input type="text" id="zip_code" maxlength="5"><br />
<label for="description">Description</label>
<textarea id="description" rows="5" columns="10"></textarea>
<br>
<input type="submit" name="submit">
</form>
的add_event.php插入代碼:
<?php
require_once '../app_config.php';
require_once '../database_connection.php';
require_once '../authorize.php';
session_start();
// Authorize any user, as long as they're logged in
authorize_user();
//Get the user ID of the user to show
$user_id = $_SESSION['user_id'];
$select_query = "SELECT first_name, last_name FROM users WHERE user_id = " . $user_id;
// Run the query
$result = mysql_query($select_query);
if ($result) {
$row = mysql_fetch_array($result);
$first_name = $row['first_name'];
$last_name = $row['last_name'];
}
$name = $first_name . ' ' . $last_name;
$event_name = trim($_POST['event_name']);
$date = trim($_POST['date']);
$zip_code = trim($_POST['zip_code']);
$description = trim($_POST['description']);
// $date = "2012-08-22";
$newdate = date("Y-m-d", strtotime($date));
// $event_name = "test";
// $zip_code = "22153";
// $description = "test";
$insert_sql = sprintf("INSERT INTO events " .
"(name, user_profile_id, event_name, date, zip_code, description) " .
"VALUES ('%s', %d, '%s', '%s', '%s', '%s');",
mysql_real_escape_string($name),
mysql_real_escape_string($user_id),
mysql_real_escape_string($event_name),
mysql_real_escape_string($newdate),
mysql_real_escape_string($zip_code),
mysql_real_escape_string($description));
//insert the user into the database
mysql_query($insert_sql);
echo $insert_sql;
?>
提前很多感謝。
你的PHP錯誤報告是否已開啓?你有沒有任何錯誤? – Maximus2012
你沒有包括你的表格的代碼,日期一個將特別有用 – Luke
錯誤檢查這個最簡單的方法將回聲/ var_dump您的$ _Posts,以便您可以驗證他們包含可用的數據 –