cart.phpitems.php Der folgende Code zeigt Produkte in den Warenkorb eines Benutzers.unter Verwendung der Schaltfläche senden Benutzer können einzelne Elemente in der löschen cart.Es ist in der Datei cart.php gespeichert.Dieser Code funktioniert gut.Übergeben Schaltfläche funktioniert nicht in div (Inhalt von denen geladen werden mit. Load() in jQuery)
<?php
session_start();
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<body>
<div class="txt-heading">Shopping Cart</div>
<table cellpadding="10" cellspacing="1">
<tbody>
<tr>
<th><strong>Name</strong></th>
<th><strong>Quantity</strong></th>
<th><strong>Price</strong></th>
</tr>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$ip = $_SERVER['REMOTE_ADDR'];
$sql = "SELECT * FROM cart where ip='".$ip."'";
$result = mysqli_query($conn, $sql);
$item_total =0;
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
?><form method="post" action="" id="cart1">
<tr>
<td><strong><?php echo $row["name"]; ?></strong></td>
<td><?php echo $row["qty"]; ?></td>
<td align=right><?php echo "Rs.".$row["price"]; ?></td>
<input name="no" type="hidden" value="<?php echo $row["orderno"] ?>" />
<td><input type="submit" name="submit" id="submit"/></td>
</tr>
</form>
<?php
$item_total += ($row["price"]*$row["qty"]);
}
}
?>
<?php if ($_POST['submit']) {
$or=$_POST['no'];
$sql = "delete FROM cart where orderno='".$or."'";
$result = mysqli_query($conn, $sql);
header("Location: ".$_SERVER['PHP_SELF']);}
?>
<tr>
<td colspan="5" align=right><strong>Total:</strong> <?php echo "Rs.".$item_total; ?></td>
</tr>
</tbody>
</table>
</body>
</html>
Das Problem, dass, wenn ich das von einer anderen Seite in einen div laden items.php mit
<script>
$(document).ready(function(){
setInterval(function(){
$("#cart").load('cart.php')
}, 20);
});
</script>
Die cart.php im div #cart ordnungsgemäß geladen wird, aber wenn ich auf "Senden" klicke, passiert nichts. Bitte beachten Sie, dass beim Klicken auf "Senden in Warenkorb.php" das Produkt aus der Datenbank gelöscht wurde.
Kann jemand bitte erklären, wie man dieses Problem behebt?
leid Kumpel, im Code in Anführungszeichen Typo ... ('click', '# submit', .... – gavgrif
@gavgrif Dank Ich habe es bearbeitet – brk
dritten Mal richtig :)) – gavgrif