Hi guys,
i am new in PHP and also MYSQL, i have been working on a project but could not get this particular module done. I want to extract a few information from one database(master_name) with fields (name, price,description,id...bla bla) to insert it into another database. The problem is that i want to extract and send 2 information at the same time. Here are my codes
<?php
//connect to database
$mysqli = mysqli_connect("localhost", "root", "", "rms");
if (!$_POST) {
//haven't seen the selection form, so show it
//get parts of records
$get_list_sql = "SELECT price, id, name,
CONCAT_WS(', ', name) AS display_name
FROM master_name WHERE availability = 'available'
ORDER BY name";
$get_list_res = mysqli_query($mysqli, $get_list_sql) or die(mysqli_error($mysqli));
if (mysqli_num_rows($get_list_res) < 1) {
//no records
$display_block .= "<p><em>Sorry, no records to select!</em></p>";
} else {
//has records, so get results and print in a form
$display_block .= "
<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">
<p><strong>Select an Item:</strong><br/>
<select name=\"food_name\">
<option value=\"\">-- Select One --</option>";
while ($recs = mysqli_fetch_array($get_list_res)) {
$id = $recs['id'];
$price = $recs['price'];
$display_name = stripslashes($recs['display_name']);
//$display_block .= "<option value=\"".$id."\">".$display_name."</option>";
$display_block .= "<option value=\"".$display_name."\">".$display_name."</option>";
}
$display_block .= "
</select>
<p><strong>Quantity:</strong><br/>
<input type=\"int\" name=\"quantity\" size=\"2\" maxlength=\"2\">
</p>
<p><strong>Comment</strong><br/>
<input type=\"varchar\" name=\"comment\" size=\"50\" maxlength=\"200\">
</p>
<p><strong>Table Number:</strong><br/>
<input type=\"radio\" name=\"table_no\" value=\"Table 1\" checked> 1 <br/>
<input type=\"radio\" name=\"table_no\" value=\"Table 2\"> 2 <br/>
<input type=\"radio\" name=\"table_no\" value=\"Table 3\"> 3 <br/>
<input type=\"radio\" name=\"table_no\" value=\"Table 4\"> 4 <br/>
<input type=\"radio\" name=\"table_no\" value=\"Table 5\"> 5 <br/>
<input type=\"radio\" name=\"table_no\" value=\"Table 6\"> 6 <br/>
<input type=\"radio\" name=\"table_no\" value=\"Table 7\"> 7 <br/>
<input type=\"radio\" name=\"table_no\" value=\"Table 8\"> 8 <br/>
<input type=\"radio\" name=\"table_no\" value=\"Table 9\"> 9 <br/>
<input type=\"radio\" name=\"table_no\" value=\"Table 10\"> 10
</p>
<p><input type=\"submit\" name=\"submit\" value=\"Submit Selected Entry\"></p>
</form>";
}
//free result
mysqli_free_result($get_list_res);
} else if ($_POST) {
//check for required fields
if (($_POST["food_name"] == "") || ($_POST["quantity"] == "")) {
header("Location: orderplacing.php");
exit;
}
$get_rec_no = "SELECT receipt_no FROM items_order ORDER BY receipt_no DESC";
$res = mysqli_query($mysqli, $get_rec_no) or die(mysqli_error($mysqli));
$first_row = mysqli_fetch_row($res);
foreach ($first_row as $key => $value)
$latest_rec_no = $value;
//$debug = 0;
if ($_POST["comment"] == "")
{
$query = "INSERT INTO table_name (timeInserted, name, quantity, price, comment, status, table_no, receipt_no, table_stat)
VALUES (now(), '".$_POST["food_name"]."', '".$_POST["quantity"]."', '$get_list2_sql', 'normal order' , 'pending', '".$_POST["table_no"]."'," . ($latest_rec_no+1) . ", 'occupied') ";
$query1 = ereg_replace("table_name","items_order",$query);
$query2 = ereg_replace("table_name","arc_order",$query);
mysqli_query($mysqli, $query1) or die(mysqli_error($mysqli));
mysqli_query($mysqli, $query2) or die(mysqli_error($mysqli));
}
else
{
$query = "INSERT INTO table_name (timeInserted, name, quantity, comment, status, table_no,receipt_no)
VALUES (now(), '".$_POST["food_name"]."', '".$_POST["quantity"]."', '".$_POST["comment"]."' , 'pending', '".$_POST["table_no"]."'," . ($latest_rec_no+1) . ") ";
$query1 = ereg_replace("table_name","items_order",$query);
$query2 = ereg_replace("table_name","arc_order",$query);
mysqli_query($mysqli, $query1) or die(mysqli_error($mysqli));
mysqli_query($mysqli, $query2) or die(mysqli_error($mysqli));
}
mysqli_close($mysqli);
$display_block = "<p>Your entry has been queued. Would you like to <a href=\"orderplacing.php\">add another order</a>?</p>";
}
?>
My problem is i want to insert value food_name and also price for the selected item from master_name before inserting into the other tables. Can anyone help me out. What is missing??? I just cannot seem to capture the price i need. Please help me... Thank you.