2016-02-02 63 views
-2

當我運行此文件時出現文件錯誤的意外結束。下面是代碼。PHP中的文件結尾錯誤

<?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); 
 
\t \t 
 
\t \t 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(); 
 
?>

+0

你錯過了' 「'在此行'$語句= $ dbh->準備(」 INSERT INTO data_centre_users(名字,姓氏,要求,目的,accessed_by,描述,booking_time,access_time) 值(:如first_name,:姓氏,:請求,:目的,:accessedby,:說明,NOW(),:accessdate); \t \t \t \t值( '$如first_name' ,'$ last_name','$ request','$ purpose','$ accessibleby','$ description',NOW() ,'$ accessdate')「<--- Right Here); ' – cmorrissey

+1

即使是SO的代碼格式化程序也能找到錯誤。您忘記關閉一個報價和所有從該點開始的所有內容,直到文件結尾被解釋爲(n不完整)字符串。 – axiac

回答

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')"); 
相關問題