2016-02-21 88 views
0

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 ''1235'='1235' WHERE username='wafflezzz'' at line 1' in /home/wafflez3/public_html/Project SA Theme/ipn/set.php:14 Stack trace: #0 /home/wafflez3/public_html/Project SA Theme/ipn/set.php(14): PDOStatement->execute() #1 {main} thrown in /home/wafflez3/public_html/Project SA Theme/ipn/set.php on line 14錯誤:SQLSTATE [42000]當我嘗試更新表中的值時

當我使用此代碼將空值更改爲值時,出現該錯誤。

<?php session_start(); require "../pdo_connect.php"; $usrname = $_SESSION["username"]; ?> 
<title>Loading...</title> 
<?php 
$checker = $conn->prepare("SELECT * FROM transactions WHERE payer_user=:username AND success='1'"); 
$checker->bindParam(":username", $usrname); 
$checker->execute(); 

while ($row = $checker->fetch(PDO::FETCH_BOTH)) { 

    $paidscript = $row["item_name"]; 
    $sql = $conn->prepare("UPDATE us SET :script=:script WHERE username=:userr"); 
    $sql->bindParam(":userr", $usrname); 
    $sql->bindParam(":script", $paidscript); 
    $sql->execute(); 
    echo "You can now view the script!"; 




} 
+0

你確定它並不意味着是'$ SQL = $ conn->準備(「更新我們將腳本=:腳本其中username = :userr「);'? – Matt

+0

這一行$ sql = $ conn-> prepare(「UPDATE us SET:script =:script WHERE username =:userr」);從腳本列名稱中刪除':' –

+0

其:腳本,因爲我想獲取腳本名,如果你將腳本名設置爲腳本名,我的系統就可以工作,那麼你需要腳本。這是我的愚蠢,但那就是我是如何做到的。此外,腳本名獲得一列 – Ch33ky

回答

1

$sql = $conn->prepare("UPDATE us SET :script=:script WHERE username=:userr");

大概應該是

$sql = $conn->prepare("UPDATE us SET script=:script WHERE username=:userr");

你根本就不是意味着綁定字段名稱參數。如果你這樣做,它會給你這樣的錯誤。

爲了有一個動態的字段名,你就必須這樣做:

$paidscript = $row["item_name"]; 
$sql = $conn->prepare("UPDATE us SET {$paidscript}=:script WHERE username=:userr"); 

雖然你真不該動態進入一個領域,如果從用戶輸入值的。

+0

我怎麼能:腳本=:腳本工作,還有什麼我必須添加 – Ch33ky

+0

閱讀http://stackoverflow.com/questions/16885091/dynamically-change-column-name-in-pdo-statement。你不能將參數綁定到字段名稱。 – Matt

0

$sql = $conn->prepare("UPDATE us SET {$paidscript}=:script WHERE username=:userr"); 

取而代之的是:

$sql = $conn->prepare("UPDATE us SET :script=:script WHERE username=:userr"); 
相關問題