2014-04-19 3 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()를 모두했을 때 정확하다고 말할 수있다.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

"set"후에 열 이름 주변에 작은 따옴표가 추가 된 것처럼 보입니다. 그것들은 그것을 망칠 것이고, 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' 
관련 문제