2014-02-17 6 views
1

메서드에 전달 된 문자열과 일치하는 행을 삭제하려고합니다. 문자열로 행을 삭제하는 PHP

$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass); 
$data = array($_POST["username"]); 


$stmt = $conn->prepare("DELETE FROM Table WHERE username = username=? "); 
$stmt->execute($data); 

나는 SQL 문의 몇 가지 조합을 시도했지만

답변

0

스팟에게 SQL 오류를 작업 하나를 얻을 수 없습니다

username = username=?

될해야

username = ?

1
// Store user input in a variable 
$data = $_POST["username"]; 

// Prepare the query 
$stmt = $conn->prepare("DELETE FROM Table WHERE username=:username"); 

// Bind the value 
$stmt->bindValue(':username', $data, PDO::PARAM_STR); 

// Execute the query 
$success = $stmt->execute(); 

// If query succeeded, display the number of affected rows 
if ($success) { 
    $affected_rows = $stmt->rowCount(); 
    echo $affected_rows; 
} 
관련 문제