2017-08-10 9 views
0
Subject Update Failed!!You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1 
I am stuck here can anyone help me what I am missing in this code.The error is in Update Query. 

Dreamviwerコードエディタソフトウェアを使用していますが、コードを記述するときに文法エラーは発生しません。 //フォームほとんどの場合は、パラメータの名前を入力ミス件名の更新に失敗しました

$id= $current_subject["Id"]; 
$name=mysql_prep($_POST["Name"]); 
$position=(int)$_POST["Position"]; 
$visible=(int)$_POST["Visible"]; 

$query="UPDATE subjects SET Name='{$name}',Position=$position,Visible=$visible WHERE Id={$id}"; 

$result= mysqli_query($conn, $query); 
if($result && mysqli_affected_rows($conn)==1){ 
    //success 
    $_SESSION["message"]="Subject updated."; 
    redirect_to("manage_content.php"); 

}else{ 

    //Failure 
    $message="Subject Update Failed" . $conn->error; 

    } 
+0

mysql_prepとは何ですか?あなたはUPDATEクエリで{}を削除する必要があると思います。 –

+0

'echo $ query'。構文エラーを見つけたら、あなたの尻尾をタックしてください。 –

答えて

1

を処理し、最初にパラメータをЕcho

そして、SQLインジェクションを防ぐために準備されたステートメントを使用します。。

$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass); 
$query="UPDATE subjects SET Name = ? ,Position = ?,Visible = ? WHERE Id = ?"; 
$stmt = $dbh->prepare($query); 
$stmt->bindParam(1, $name); 
$stmt->bindParam(2, $position); 
$stmt->bindParam(3, $visible); 
$stmt->bindParam(4, $id); 
$stmt->execute(); 
$stmt->fetchAll(); 

さらなる読書:PDO

関連する問題