我想選擇PHP代碼中的數據,並從mysql數據庫中選擇數據,然後選定的數據將被刪除!這是我的一般想法。從選定菜單中刪除數據庫中的數據
我寫的代碼,第一個代碼是從數據庫打印數據,以允許用戶選擇數據,這是第一次代碼:
<form method="POST" action="deleteacc.php" name='monitor' id='monitor'>
<select name="drivers"><option>Please Select the sensor id that you want to delete :</option>
<?php
$uid=$_SESSION['uid'];
$dbName = "senior"; //Database name
$db = mysql_connect ("localhost","root","hahaha1") or die("Unable To Connect "); //Connect to database
$test= mysql_select_db ($dbName,$db) or die("Unable to select database"); //Test Connection
$result=mysql_query("SELECT * FROM accelerometer ");
while ($row=mysql_fetch_array($result))
{
$sid = $row['sid'];
$x=$row['x'];
$y=$row['y'];
$z=$row['z'];
$date=$row['date'];
$time=$row['time'];
echo "<option name=$sid' value='$sid'> Device ID: $sid</option>";
}
mysql_close($db);
?>
</select></center>
<br>
<center> <input type="submit" value= " Monitor " name="submit" ><br /><br /> </center>
</form>
我的第二個代碼刪除所選數據:
<?php
$dbh=mysql_connect("localhost", "root", "hahaha1") or die (mysql_error());
mysql_select_db ("senior");
extract($_POST);
$mySql="DELETE FROM accelerometer WHERE sid=$drivers";
mysql_query($mySql) or die (mysql_error());
echo "<h2> User info was deleted successfully</h2>";
echo "<h3>To go back to adminstration control click <a href='member.php'>Here!</a> or to delete another accelerometer value click <a href='deleteacc2.php'>Here!</a></h3>";
mysql_close($dbh);
?>
我的問題是,當我從菜單中選擇數據並按下監視器顯示,我這個錯誤:
Unknown column 'bedoor' in 'where clause'
關於如何解決我的問題的任何想法,請?
也許你delte SQL語句是由$驅動變量損壞。嘗試消除有問題的字符,在刪除查詢之前編寫以下語句:'$ driver = addslashes($ driver);' – Muatik
我試過你說的錯誤顯示給我:致命錯誤:調用未定義的函數addlslahes()在C:\ AppServ \ www \ senior \ deleteacc.php在線61 –
對不起,有一個錯字。我剛剛糾正了它。看看這個:http://php.net/addslashes並根據ROY的答案更改你的代碼。 – Muatik