我試圖更新行或記錄,我不斷收到一個錯誤:更新記錄與PDO一直收到錯誤
Parse error: syntax error, unexpected '$sql' (T_VARIABLE) in C:\wamp\www\Systems\update_process.php on line 11
我不知道如何去解決這個我試過很多東西。
<?php
$db_host = "localhost";
$db_username = "root";
$db_pass = "";
$db_name = "systems_requests";
try{
$db = new PDO('mysql:host='.$db_host.';dbname='.$db_name,$db_username,$db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING)
$sql = 'UPDATE requests SET lanId= :lanId, name= :name, department= :department,manager= :manager,request= :request,request_description= :request_description, request_comments= :request_comments,status= :status,comments= :comments,compUser= :compUser, compDt= :comDt WHERE id= :id';
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':id', $_POST['lanId'], PDO::PARAM_INT);
$stmt->bindParam(':lanId', $_POST['lanId'], PDO::PARAM_STR);
$stmt->bindParam(':name', $_POST['$name'], PDO::PARAM_STR);
$stmt->bindParam(':department', $_POST['department'], PDO::PARAM_STR);
$stmt->bindParam(':manager', $_POST['manager'], PDO::PARAM_STR);
$stmt->bindParam(':request', $_POST['request'], PDO::PARAM_STR);
$stmt->bindParam(':request_description', $_POST['request_description'], PDO::PARAM_STR);
$stmt->bindParam(':request_comments', $_POST['request_comments'], PDO::PARAM_STR);
$stmt->bindParam(':status', $_POST['status'], PDO::PARAM_STR);
$stmt->bindParam(':comments', $_POST['comments'], PDO::PARAM_STR);
$stmt->bindParam(':compUser', $_POST['compUser'], PDO::PARAM_STR);
$stmt->bindParam(':comDt', $_POST['comDt'], PDO::PARAM_INT);
$stmt->execute();
header('Location:index.php');
}catch(PDOException $exception){
echo "Error: " . $exception->getMessage();
}
?>
訂正代碼,但仍然沒有工作獲取錯誤信息致命錯誤:調用一個成員函數準備()的非對象在C於:\瓦帕\ WWW \上線系統\ update_process.php 12
<?php
$db_host = "localhost";
$db_username = "root";
$db_pass = "";
$db_name = "systems_requests";
try{
$db = new PDO('mysql:host='.$db_host.';dbname='.$db_name,$db_username,$db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$db = 'UPDATE requests SET id=:id, lanId= :lanId, name= :name, department= :department,manager= :manager,request= :request,request_description= :request_description, request_comments= :request_comments,status= :status,comments= :comments,compUser= :compUser, compDt= :comDt WHERE id= :id';
$stmt = $db->prepare($sql);
$stmt->bindParam(':id', $_POST['id'], PDO::PARAM_INT);
$stmt->bindParam(':lanId', $_POST['lanId'], PDO::PARAM_STR);
$stmt->bindParam(':name', $_POST['$name'], PDO::PARAM_STR);
$stmt->bindParam(':department', $_POST['department'], PDO::PARAM_STR);
$stmt->bindParam(':manager', $_POST['manager'], PDO::PARAM_STR);
$stmt->bindParam(':request', $_POST['request'], PDO::PARAM_STR);
$stmt->bindParam(':request_description', $_POST['request_description'], PDO::PARAM_STR);
$stmt->bindParam(':request_comments', $_POST['request_comments'], PDO::PARAM_STR);
$stmt->bindParam(':status', $_POST['status'], PDO::PARAM_STR);
$stmt->bindParam(':comments', $_POST['comments'], PDO::PARAM_STR);
$stmt->bindParam(':compUser', $_POST['compUser'], PDO::PARAM_STR);
$stmt->bindParam(':comDt', $_POST['comDt'], PDO::PARAM_INT);
$stmt->execute();
header('Location:index.php');
}catch(PDOException $exception){
echo "Error: " . $exception->getMessage();
}
?>
正確的代碼,現在和工作
<?php
$db_host = "localhost";
$db_username = "root";
$db_pass = "";
$db_name = "systems_requests";
try{
$db = new PDO('mysql:host='.$db_host.';dbname='.$db_name,$db_username,$db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$sql = 'UPDATE requests SET id=:id, lanId= :lanId, name= :name, department= :department,manager= :manager,request= :request,request_description= :request_description, request_comments= :request_comments,status= :status,comments= :comments,compUser= :compUser, compDt= :comDt WHERE id= :id';
$stmt = $db->prepare($sql);
$stmt->bindParam(':id', $_POST['id'], PDO::PARAM_INT);
$stmt->bindParam(':lanId', $_POST['lanId'], PDO::PARAM_STR);
$stmt->bindParam(':name', $_POST['$name'], PDO::PARAM_STR);
$stmt->bindParam(':department', $_POST['department'], PDO::PARAM_STR);
$stmt->bindParam(':manager', $_POST['manager'], PDO::PARAM_STR);
$stmt->bindParam(':request', $_POST['request'], PDO::PARAM_STR);
$stmt->bindParam(':request_description', $_POST['request_description'], PDO::PARAM_STR);
$stmt->bindParam(':request_comments', $_POST['request_comments'], PDO::PARAM_STR);
$stmt->bindParam(':status', $_POST['status'], PDO::PARAM_STR);
$stmt->bindParam(':comments', $_POST['comments'], PDO::PARAM_STR);
$stmt->bindParam(':compUser', $_POST['compUser'], PDO::PARAM_STR);
$stmt->bindParam(':comDt', $_POST['comDt'], PDO::PARAM_INT);
$stmt->execute();
}catch(PDOException $exception){
echo "Error: " . $exception->getMessage();
}
?>
你錯過了',''在$ DB->的setAttribute(PDO :: ATTR_ERRMODE,PDO結束:: ERRMODE_WARNING)' – andrewsi 2014-11-08 13:26:53
未定義的變量:pdo在C:\ wamp \ www \ Systems \ update_process.php上,並且在C:\ wamp \ www \ Systems \第12行的update_process.php現在我添加了這些錯誤; – Donny 2014-11-08 13:31:04
第12行是$ stmt = $ pdo-> prepare($ sql); – Donny 2014-11-08 13:31:50