this is my code though i am not sure what i am missing to remove the error:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Week 8 Exercise 4</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<?php
require_once("conn.php");
if(isset($_POST['quantity'])) {
$quantityinstock = $_POST['quantity'];
}
$quantityinstock = $dbConn->escape_string($_POST['quantity']);
$sql = "select name, quantityInStock, price from product where quantityinstock = '$quantityinstock'";
$results = $dbConn->query($sql)
or die ('Problem with query: ' . $dbConn->error);
?>
<h1>Product with stock > <?php echo "$quantityinstock"; ?> </h1>
<table>
<tr>
<th>Name </th>
<th>Quantity In Stock</th>
<th>Price</th>
</tr>
Autumn 2020
Technologies for Web Applications 300582
Page 3 of 5
<?php
while ($row = $results->fetch_assoc()) { ?>
<tr>
<td><?php echo $row["name"]?></td>
<td><?php echo $row["quantityInStock"]?></td>
<td><?php echo $row["price"]?></td>
<!-- output the other fields here from the $row array -->
</tr>
<?php }
$dbConn->close(); ?>
</table>
</body>
</html>
this is my code though i am not sure what i am missing to remove the error:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Week 8 Exercise 4</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<?php
require_once("conn.php");
if(isset($_POST['quantity'])) {
$quantityinstock = $_POST['quantity'];
}
$quantityinstock = $dbConn->escape_string($_POST['quantity']);
$sql = "select name, quantityInStock, price from product where quantityinstock = '$quantityinstock'";
$results = $dbConn->query($sql)
or die ('Problem with query: ' . $dbConn->error);
?>
<h1>Product with stock > <?php echo "$quantityinstock"; ?> </h1>
<table>
<tr>
<th>Name </th>
<th>Quantity In Stock</th>
<th>Price</th>
</tr>
Autumn 2020
Technologies for Web Applications 300582
Page 3 of 5
<?php
while ($row = $results->fetch_assoc()) { ?>
<tr>
<td><?php echo $row["name"]?></td>
<td><?php echo $row["quantityInStock"]?></td>
<td><?php echo $row["price"]?></td>
<!-- output the other fields here from the $row array -->
</tr>
<?php }
$dbConn->close(); ?>
</table>
</body>
</html>
Share
Improve this question
edited May 14, 2020 at 5:41
Arushi Rajput
456 bronze badges
asked May 14, 2020 at 4:14
rogerroger
1
1 Answer
Reset to default 1This doesn't seem to have anything to do with WordPress, but the problem is simple: You're still using $_POST['quantity']
outside of isset()
.
You're checking isset()
here:
if(isset($_POST['quantity'])) {
$quantityinstock = $_POST['quantity'];
}
But then you're immediately using it without the check anyway:
$quantityinstock = $dbConn->escape_string($_POST['quantity']);
You should not be using $_POST['quantity']
without a check for isset()
.