Im currently attempting to create a small program in php/sqlite (I am VERY new to php and sqlite) where I can populate the quantity of already stored products and also add in new products aswel.
I already have a database made which has numerous entries within it.
Ive managed to create this code however it isn't returning anything or giving me any errors.
Would someone be able to point out what ive done wrong or a possible solution?!
Here is my code...
<?php
$db=sqlite_open("warehouse.db");
if(isset( $_POST['warehouse']) && strcmp($_POST['warehouse'],"") !=0 ){
$ItemID = sqlite_escape_string($_POST["warehouse"]);
$ItemName=$_POST['warehouse'];
$Quantity=$_POST['warehouse'];
$qr="UPDATE warehouse SET Quantity = $Quantity WHERE ItemName = (SELECT id FROM warehouse WHERE itemName='$ItemName')";
sqlite_query($db,$qr);
echo "<h2>". "Show warehouse"."</h2>";
echo "<table border=1>
";
echo "</br>
";
$result=sqlite_query($db,"SELECT * from warehouse WHERE warehouse.ItemName = warehouse.id");
echo "<th>Item ID</th><th>Item Name</th><th>Item Quantity</th>
";
while($row=sqlite_fetch_array($result,SQLITE_ASSOC))
{
echo "<tr>
";
echo "<td>" . $row['warehouse.ItemId'] . "</td>
";
echo "<td>" . $row['warehouse.ItemName'] . "</td>
";
echo "<td>" . $row['warehouse.Quantity'] . "</td>
";
echo "</tr>
";
}
echo "</table>
";
}
sqlite_close($db);
?>
The code you've shown is wrapped in:
if(isset( $_POST['warehouse']) && strcmp($_POST['warehouse'],"") !=0 ){
// all your code, including showing the current data
}
So it will only generate output when you POST something to it, ie submit a form to it. If you just visit that page in a browser, you're doing a GET, so the only thing that happens is your db is opened and immediately closed, nothing inside the POST test executes, and no output is generated for the browser.
You probably want to move the "}" which closes the POST test up to just above your "Show Warehouse" title, that way you'll at least see your table of data when just using GET.
if(isset( $_POST['warehouse']) && strcmp($_POST['warehouse'],"") !=0 ){
// code for updating data
}
echo "<h2>". "Show warehouse"."</h2>";
// rest of your display code