我正在研究一個非常基礎的PHP程序。我對PHP很陌生,並且知道我使用的是舊版本,即不是PDO。我一直在研究這一段時間,並不知道爲什麼它不工作。PHP通過表格從表中刪除問題
我只是試圖從我的表中刪除一個匹配用戶輸入的項目。
((也如果任何人有任何簡單的建議,我可以使用有一個更安全的刪除功能,因爲我知道,如果用戶輸入「R」例如,表中的一大部分將被刪除))
這裏是我的代碼:
<?php
//delete from table
if(isset($_POST['delete1']))
{
$deletevalue = $_POST['deletevalue'];
$deletequery = "DELETE FROM users WHERE deletevalue = $deletevalue";
$deleteresult = deleteTable($deletevalue);
}
function deleteTable ($deletevalue)
{
$connect = mysqli_connect("localhost", "root", "", "test_db");
$delete_fromTable = mysqli_query($connect, $deletevalue);
print mysqli_error($connect);
}
?>
<!DOCTYPE html>
<html>
<body>
<form action="zzz.php" method="post" />
<p> Remove Item: <input type="text" name="deletevalue" placeholder="Item
Name" /> </p>
<input type="submit" name ="delete1" value="submit" />
</form>
</body>
</html>
[Little Bobby](http://bobby-tables.com/)說*** [你的腳本存在SQL注入攻擊風險。](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql -injection-in-php)***瞭解[MySQLi](http:// http:// http://my.wikipedia.org/wiki/Prepared_statement) php.net/manual/en/mysqli.quickstart.prepared-statements.php)。即使[轉義字符串](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string)是不安全的! –
「請不要火焰」並不意味着你會逃避所有的評論,告訴你你的代碼有多麼嚴重。 –
不可能告知爲什麼在不知道數據庫表結構的情況下無法正常工作。 –