When I add a record in my database, it is successful, but instead of the data entered, it returns 1 instead. Here is the code of the form.
<?php
include('session.php');
$productname = isset($_POST['productname']);
$stocks = isset($_POST['stocks']);
$category = isset($_POST['category']);
$price = isset($_POST['price']);
$addrecord = "insert into inventory values (' ', '$productname', '$stocks', ' ', ' ', '$category', '$price')";
if (!empty($productname) && !empty($stocks) && !empty($category) && !empty($price)) {
$query = mysqli_query($db, $addrecord);
echo 'Inventory record added';
}
?>
<html>
<head>
<title>New Inventory Record | Healthy Eats Point of Sales System</title>
<link rel="stylesheet" href="css/main.css" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
</head>
<body>
<div id="main">
<div id="nav">
<ul>
<li><a href="system_transactions.php" class="button">TRANSACTIONS</a></li>
<li><a href="#" class="button">INVENTORY</a></li>
<li><a href="#" class="button">FINANCES</a></li>
<li><a href="#" class="button">AUDIT TRAIL</a></li>
<div class="pic"><img src="images/pastedImage0.png"></div><br>
<p style="float: right; margin:3% -11%"><?php echo $login_session; ?><br><a href="logout.php" style="font-weight: bold">Log Out</a></p>
</ul>
</div>
<div id="table">
<a href="system_inventory.php" class="button">BACK</a>
<br /><br />
<h3>New Inventory Record</h3>
<form action="new_record.php" method="post">
<table style="border: 0;">
<tr>
<th>Product Name</th>
<td><input type="text" name="productname" autocomplete="off"></td>
</tr>
<tr>
<th>Stocks</th>
<td><input type="text" name="stocks"></td>
</tr>
<tr>
<th>Category</th>
<td><select name="category">
<option value="">Choose category...</option>
<option value="Vegetarian">Vegetarian</option>
<option value="Burrito">Hearty Burrito</option>
<option value="Green Servings">Green Servings</option>
<option value="Rice Meals/Toppings">Rice Meals/Toppings</option>
<option value="Pasta">Pasta</option>
<option value="Skizza">Skizza</option>
<option value="Sandwiches">Sandwiches</option>
<option value="Pancakes/Cakes">Pancakes/Cakes</option>
<option value="Juices/Beverages">Juices/Beverages</option>
</select></td>
</tr>
<tr>
<th>Price</th>
<td><input type="text" name="price" autocomplete="off"></td>
</tr>
<tr>
<th><input type="submit" value="ADD RECORD"> <input type="reset" value="ERASE ALL"></th>
</tr>
</table>
</form>
</div>
</div>
It returns 1 for every column. Here is a photo of a new record entered.
https://i.stack.imgur.com/0EOz9.jpg
Let's say the record entered are the following:
- Name: Grilled Veggies
- Stocks: 10 (so that committed and available columns become 0 and 10, latter is derived)
- Category: Vegetarian (from option select list)
- Price: 115.00
Then Add Record button is entered. Instead of the details above, it returns the picture above. Is there any workaround on this?