2014-04-19 102 views
1
<script> 
function enter_edit(column) 
{ 
var username = '<?php echo $username ;?>'; 
var password = '<?php echo $password ;?>'; 
var input = prompt("Please enter a new " + column , ""); 
//window.alert(input); 
//window.alert(column); 
//window.alert(username); 
//window.alert(password); 
$.ajax({ 
     type: "POST", 
     url: "edit_account.php", 
     data: { input:input , username:username , password:password, column:column } 

    }); 
window.alert("Account has been edited"); 
window.location = 'manage_account.php'; 
} 
</script> 

我有這個功能,它需要用戶名和密碼已經被查詢過的帳戶,獲取用戶想要的選定列更改爲等等。我將這些變量發送到edit_account.php來執行UPDATE查詢。至於我可以告訴所有的變量是正確的,當我做了一個window.alert()爲他們所有4。爲什麼我的MYSQL UPDATE語句不更新?

<?php 

    require ('connect.php'); 

    $input = $_POST['input']; 
    $username = $_POST['username']; 
    $password = $_POST['password']; 
    $column = $_POST['column']; 


    $link = my_connect(); 

    $editAccount = $link->query("update AdvancedUser set '".$column."' = '".$input."' where UserName = '".$username."' and UserPassword = '".$password."'"); 
    //$deleteAccount = $link->query("delete from AdvancedUser where UserName = '".$username."' AND UserPassword = '".$password."'"); 

    $editAccount->close(); 
    $link->close(); 


?> 

這是在我試圖使用MySQL UPDATE,使我改變然而與此代碼它改變不了什麼edit_account.php。當我試圖把刪除查詢,而不是(只是爲了測試,如果我的連接不工作),它工作得很好。有任何想法嗎?再次感謝

+1

你到底在你的打印密碼代碼,老兄?!?!?!?!你有沒有聽說過[PHP會話](http://www.php.net/manual/en/features.sessions.php)? – DontVoteMeDown

+0

安全性不是此項目的重中之重,也適用於管理員帳戶。至於那裏的密碼忽略它們。 – Darwin

+1

看起來您在「設置」後在列名稱周圍有多餘的單引號。那些會毀了它,MySQL會認爲它不是列名,而是一個字符串。 – dgig

回答

1

變化:

$editAccount = $link->query("update AdvancedUser set '".$column."' = '".$input."' where UserName = '".$username."' and UserPassword = '".$password."'"); 

到:

$editAccount = $link->query("update AdvancedUser set $column = '".$input."' where UserName = '".$username."' and UserPassword = '".$password."'"); 
                ^_______^--without quotes 
1

試試這個

<?php 
     require ('connect.php'); 

     $input = $_POST['input']; 
     $username = $_POST['username']; 
     $password = $_POST['password']; 
     $column = $_POST['column']; 

     $link = my_connect(); 

     $editAccount = $link->query("update AdvancedUser set $column = '".$input."' where 
     UserName = '".$username."' and UserPassword = '".$password."'"); 
     //$deleteAccount = $link->query("delete from AdvancedUser where UserName = 
     '".$username."' AND UserPassword = '".$password."'"); 

     $editAccount->close(); 
     $link->close(); 
    ?> 
1

刪除周圍$列中的報價。

取而代之的是:

$editAccount = $link->query("update AdvancedUser set '".$column."' = '".$input."' where UserName = '".$username."' and UserPassword = '".$password."'"); 

試試這個:

$editAccount = $link->query("update AdvancedUser set ".$column." = '".$input."' where UserName = '".$username."' and UserPassword = '".$password."'"); 

當您迴應此查詢它看起來像:

update AdvancedUser set ColumnName = 'ColumnValue' where UserName = 'username' and UserPassword = 'password'