2014-02-17 109 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; 
}