运行此文件时出现意外的文件错误.Below是代码。
<?php
include_once('/templates/header.php');
include_once('/admin/includes/db_connect.php');
session_start();
$last_id;
$first_name=$_POST['firstname'];//this values comes from html file after submitting
$last_name=$_POST['lastname'];
$request=$_POST['request'];
$purpose=$_POST['purposebuttons'];
$accessedby = $_POST['personbuttons'];
$description=$_POST['description'];
$accessdate = $_POST['date-time'];
/* Get Current Date and Time for the bookking_time field */
$booking_time=new DateTime();
$booking_time = $booking_time -> format("Y-m-d H:i:s");
$stmt= $dbh->prepare("INSERT INTO data_centre_users (first_name,last_name,request, purpose , accessed_by, description,booking_time,access_time)
values(:first_name,:last_name,:request,:purpose, :accessedby ,:description, NOW() , :accessdate);
values('$first_name','$last_name','$request','$purpose', '$accessedby' ,'$description', NOW() , '$accessdate'));
$stmt->bindParam(':first_name', $first_name);
$stmt->bindParam(':last_name', $last_name);
$stmt->bindParam(':request', $request);
$stmt->bindParam(':purpose', $purpose);
$stmt->bindParam(':accessedby', $accessedby);
$stmt->bindParam(':description', $description);
$stmt->bindParam(':accessdate', $accessdate);
if ($stmt->execute() === TRUE) {
$last_id = $dbh->lastInsertId();
echo 'New record created successfully'.'<BR>';
echo '<a href='insert_result.php'>View result</a>';
} else {
}
header ('Location: insert_result.php');
exit();
?>
&#13;
答案 0 :(得分:0)
您的查询行没有右引号。改变这一行:
$stmt= $dbh->prepare("INSERT INTO data_centre_users (first_name,last_name,request, purpose , accessed_by, description,booking_time,access_time)
values(:first_name,:last_name,:request,:purpose, :accessedby ,:description, NOW() , :accessdate);
values('$first_name','$last_name','$request','$purpose', '$accessedby' ,'$description', NOW() , '$accessdate'));
要:
$stmt= $dbh->prepare("INSERT INTO data_centre_users (first_name,last_name,request, purpose , accessed_by, description,booking_time,access_time)
values(:first_name,:last_name,:request,:purpose, :accessedby ,:description, NOW() , :accessdate);
values('$first_name','$last_name','$request','$purpose', '$accessedby' ,'$description', NOW() , '$accessdate')");