所以我想要從我的數據庫'條碼'中刪除一行信息,但它沒有發生。我點擊了提交按鈕,但它並沒有刪除我在輸入框中輸入的'itemcode'。幫幫我??商品代碼不是從數據庫中刪除
以下編輯我有一個新的錯誤
Error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
Delete.php
Testing to see if items deleted
<form action="delete.php" method="post">
<tr>
<td>Item Code: </td>
<td><input type="text" name="itemcode" autofocus></td>
<td><input type="submit" value="Delete"></td>
</tr>
</table> <br>
<?php
require_once('dbconnect.php');
$txtitemcode = (!empty($_POST['itemcode']) ? $_POST['itemcode'] : null);
$result = mysqli_query($con, "SELECT * from barcode order by itemcode");
$delete = mysqli_query($con,"DELETE FROM barcode WHERE itemcode='itemcode'");
if(!mysqli_query($con, $delete))
{
echo('Error:'.mysqli_error($con));
}
echo "<center><table border=1>";
echo"<tr>
<th>ITEM CODE:</th>
<th>Company Shipping:</th>
</tr>";
while($row = mysqli_fetch_array ($result))
{
echo"<tr>
<td align= center>".$row['itemcode']."</td>
<td align=center>".$row['item']."</td>
</tr>";
}
echo "</table>";
mysqli_close($con);
dbconnect.php
$con = mysqli_connect("localhost","root","root","db1");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else
{
echo "Connected to Database. Please Continue.";
}
Add.php該add.php工作,但刪除沒有。
php
include('dbconnect.php');
function get_posts() {
global $con;
$txtitemcode = (!empty($_POST['itemcode']) ? $_POST['itemcode'] : null);
$txtitem = (!empty($_POST['item']) ? $_POST['item'] : null);
$sql1 = "INSERT INTO barcode (itemcode, item) VALUES ('".$txtitemcode."','".$txtitem."')";
if(!mysqli_query($con, $sql1))
{
die('Error:'.mysqli_error());
}
echo "<script> alert('1 record added');
window.location.href='index.php';
</script>";
}
get_posts(); //Must have to show posts in table
mysqli_close($con);
?
使用mysql_error添加一些MySQL錯誤輸出()。這甚至不是有效的sql:mysqli_query($ con,「DELETE FROM barcode(itemcode)VALUES('」。$ txtitemcode。「')」); – maxhb
你不提供你的表結構,但是你的SQL語句沒有讀「DELETE FROM barcode WHERE itemcode ='$ txtitemcode'」(你使用了字段名'Name')。 – crafter
另外,請注意@ maxhb關於使用mysql_error()/的警告/不檢查您在黑暗中摸索的錯誤,如果出現任何錯誤。 – crafter