[EDIT] ::我在意识到表单没有将GET变量传递给php脚本后添加了表单。
我有这个工作...尝试过一些新的东西...现在我无法恢复工作了...我很as愧...
无论如何,它不是从数据库中删除该行。有人可以指出我的愚蠢错误在哪里吗?
不断得到它,所以我相信它是;
$sql = "DELETE FROM inventory WHERE prodId = $prod_id";
错误:您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册以获取正确的语法,以在第1行的''附近使用
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($form_action == 'remove'){
// remove items
$sql = "DELETE FROM `inventory` WHERE `prodId` = $prod_id";
if ($conn->query($sql) === TRUE){
$_SESSION['itemremoved'] = "true";
echo "should be gone<br>";
//header('Location: ' . $_SERVER['HTTP_REFERER']);
} else {
echo ("Error: " . mysqli_error($conn) . "<br>");
echo '</br>There was an issue deleting this item. Please verify it is still in the inventory. If the problem persists contact jworsham@pnd-productions.com';
}
}
来自单独页面的HTML / PHP部分...
<form action="invenmgt_remove.php" method="GET" name="remove">
<?PHP
if ($result->num_rows > 0) {
// output data of each row
$row_count = $result->num_rows;
$_SESSION['curcount'] = $row_count;
if ($row_count <= 0){
echo '<div class="alert alert-danger" style="margin-top; 20px;">';
echo "There are currently " . $row_count . " item(s) in the shop. Get some inventory added";
echo "</div>";
} else {
echo '<div class="alert alert-primary" style="margin-top; 20px;">';
echo "There are currently " . $row_count . " item(s) in the shop.";
echo "</div>";
}
while($row = $result->fetch_assoc()) {
// put images in array
$imgs = explode(",", $row["prodImages"]);
echo '<div class="card" style="margin-bottom:20px;">';
echo '<div class="card-header">';
echo "<strong>" . $row['prodTitle'] . "</strong> - $" . $row['prodCost'];
echo '</div>';
echo '<div class="card-body">';
echo '<input type="checkbox" name="prodIds[]" value="' . $row['prodId'] . '"> Remove<br>';
echo $row['prodDescript'] . "<br>";
foreach ($imgs as $img){
echo "<img class='img-thumbnail thumb' src='http://nerdsforhire.pnd-productions.com/images/prod/$img' width='20%' height='20%' style='margin-left:10px;'>";
}
echo '</div>';
echo '</div>';
}
echo '<input type="submit" value="submit">
</form>';
} else {
echo "Currently no inventory.";
}
$conn->close();
?>
</form>