php - Inventory system multiple tables and recipes -


i'm novice in php , extremely new databases, forgive me if stupid question:

i've built inventory system in php/mysql allows (among other things) add raw materials table, has "price_per_pound_in_dollars" , "pounds_in_stock" columns. stands, updating "pounds-in-stock" column raw material must done manually, one-at-a-time via form.

i'm wanting add database recipes contains steps needed making product, "pounds_in_stock" column can updated multiple raws @ once. please see image below.

enter image description here

basically go form, pick product drop down menu (populated recipe names doing mysqli_query), enter number of gallons want make , press submit.

the rows in recipe table have figures needed making gallon of product, of numbers in table multiplied number entered form.

so, if choose "recipe name 1" , entered "2" gallons input box. multiply "pounds_needed_per_gallon" 2 , put info mysqli_query remove correct raw "pounds_in_stock" column in "raws" table. (if makes sense).

now question:

is possible dynamically? approaching wrong way? know can result want hard coding values each recipe in php document , linking via "action =" on form page, seems exceedingly inelegant way of doing things. can't seem wrap head around how mysql.

form issue:

i created bare-bones form should include table names in drop-down menu (so recipe table can selected). can't seem table names echo out in drop down. know while loop working correctly, since there 3 options in drop-down menu, corresponds number of tables in database, problem they're blank. please see image , code below. looked on code few times, can't see made mistake. ideas?

<?php  //prepare mysql query. $product_menu_query ="show tables";  $run_product_menu_query = mysqli_query($connect, $product_menu_query); ?>   <form action="submit.php" method="post">     <span>recipe name:</span><br>     <select name="recipe">          <?php  //populates dropdown product_name database.          while ($row = mysqli_fetch_array($run_product_menu_query)) {         echo '<option value="' . $row[0] . '">' . '</option>';         }      ?>      </select><br><br>     <span>gallons:</span><br>     <input type="number" name="gallons"><br><br>     <input type="submit" value="submit"> </form> 

screenshot of form:

enter image description here

looks have (change table names , fields accordingly database actual field , table names):

$recipename = $_post['recipe']; $gallons = $_post['gallons'];  $stmt = $mysqli->prepare("select raws.id rawid, (recipe.pounds_needed_per_gallon * ?) gallons   recipename recipe   join raws raws on recipe.raw_id=raws.raw_id   raws.raw_name = ?");  $stmt->bind_param("ds", $gallons, $recipename); $stmt->execute(); $stmt->bind_result($rawid, $gallonsneeded); $stmt->close();  mysqli_query("update raws set pounds_in_stock = (pounds_in_stock - $gallonsneeded) id = $rawid"); 

edit: see need more debugging. should check values obtained through queries (i.e. rawid , gallonsneeded) , echo out errors, don't have entire code base cannot tell going wrong code.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -