Send multiple select data to database - php

i have one html table that integrates to tables from my database. What i want to do is send the data from the html select (max 2 options) to another table, but i also want to insert the "id","nome" "praia", "turno" and the day". Can someone help? If u feel that my post misses information let me know in the comments and i share that information
what i am getting
example of what i want
Form that i have to generate the days in the table:
<form method="post" name="rangee">
<label> Insira as datas </label>
<?php
// escolher os dias que vão aparecer na tabela
$sql_query = "SELECT * FROM tb_dias";
$resultset = mysqli_query($conn, $sql_query) or die("database error:" . mysqli_error($conn));
echo "<select name='dia1' size='1' class='form-select form-select-sm'>";
echo "<option value='' disabled selected hidden> Dias </option>";
while ($re = mysqli_fetch_assoc($resultset))
{
$dia1 = $re['dia'];
$id1 = $re['id_dia'];
echo "<option value=$id1>$dia1</option>";
}
?>
</select>
<?php
$sql_query = "SELECT * FROM tb_dias";
$resultset = mysqli_query($conn, $sql_query) or die("database error:" . mysqli_error($conn));
echo "<select name='dia2' size='1' class='form-select form-select-sm'>";
echo "<option value='' disabled selected hidden> Dias </option>";
while ($re = mysqli_fetch_assoc($resultset))
{
$dia2 = $re['dia'];
$id2 = $re['id_dia'];
echo "<option value=$id2>$dia2</option>";
}
?>
</select>
<input type="submit" name="enviar" class="alertButton">
</form>
Form that contains my html table:
<form method="POST" action="select.php">
<table class="table-responsive table-striped table-bordered" id="example">
<thead>
<tr>
<th>Id</th>
<th>Nome Praia</th>
<th>Turno</th>
<?php
$x = 0;
$dias = array();
while ($row = mysqli_fetch_assoc($resultsett))
{
echo "<th>" . $row['dia'] . "</th>";
$dia = $row['dia'];
$id_dia = $row['id_dia'];
array_push($dias, $id_dia);
$x++;
}
?>
</tr>
</thead>
<tbody>
<?php
$sql_query = "SELECT * FROM tb_praia";
$resultset = mysqli_query($conn, $sql_query) or die("database error:" . mysqli_error($conn));
while ($res = mysqli_fetch_assoc($resultset))
{
$id_praia = $res['id_praia'];
$nome_praia = $res['nome_praia'];
$turno = $res['turno'];
?>
<tr id="<?php $id_praia; ?>">
<td> <?php echo $id_praia; ?></td>
<td><?php echo $nome_praia; ?> </td>
<td><?php echo $turno; ?></td>
<?php for ($i = 0;$i < $x;$i++)
{
if ($id_praia % 2 == 0){
$query = "SELECT tb_nadadores.id_nadador, nome from tb_disponibilidade inner JOIN
tb_nadadores on tb_disponibilidade.id_nadador=tb_nadadores.id_nadador
where id_dia = $dias[$i] and Tarde=1 order by id_nadador ASC";
}else{
$query = "SELECT tb_nadadores.id_nadador, nome from tb_disponibilidade inner JOIN
tb_nadadores on tb_disponibilidade.id_nadador=tb_nadadores.id_nadador
where id_dia = $dias[$i] and Manhã=1 order by id_nadador ASC ";
}
$resposta = mysqli_query($conn, $query);
echo (
'<td>
<select name="nadadores[]" size="1" class="form-select multiple-select" multiple>
<br>'
);
if (mysqli_num_rows($resposta) > 0)
{
while ($teste = mysqli_fetch_assoc($resposta))
{
$nadador = $teste['nome'];
$id_nadador = $teste['id_nadador'];
echo "<option value=$id_nadador>$nadador</option>";
}
echo '</select>';
}
else{
echo 'Não foram encontrados resultados!';
}
echo "<input type='hidden' name='dias[]' value=$dias[$i] >";
echo "<input type='hidden' name='turno' value=$turno >";
echo "<input type='hidden' name='id_praia' value=$id_praia >";
echo "<input type='hidden' name='nome_praia' value=$nome_praia>";
}
}
?>
</tr>
</tbody>
</table>
<input type="submit" name="enviar" value="Enviar">
</form>
Select.php
<?php
include_once ("db_connect.php");
if(isset($_POST['enviar'])){
$nadadores_nomes = $_POST['nadadores'];
$id_praia = $_POST['id_praia'];
$nome_praia = $_POST['nome_praia'];
$turno = $_POST['turno'];
$dias = $_POST['dias'];
$dia = implode(",",$dias);
$nadadores= implode(",",$nadadores_nomes);
for ($i = 0; $i<=$dia; $i++){
for($j=1;$j<=2;$i++){
echo "Os nadadores com ids : " .$nadadores[$j]. " vao trabalhar na praia: " .$id_praia. " no turno " .$turno. " no dia" .$dia[$i];
}
}
}
?>

Related

how to query a value and add it to the date

I have a problem, you see I borrow a book getting the book_id and the date borrow is set to the date today, but each book has a days_id value that I need to add to the day of the borrow_date now I'm having trouble how can I get that date_id from the book_id I chosen and add it inside my borrow_date so that I can generate my due_date automatically
here is my PHP code
<?php
include 'connect.php';
$librarian_id = $_POST['librarian_id'];
$member_id = $_POST['member_id'];
$book_id = $_POST['book_id'];
$date_borrow = $_POST['date_borrow'];
$status_id = $_POST['status_id'];
$days = "SELECT days_id, book_id FROM book_setup
WHERE book_id = '$book_id' AND days_id = " . $row['book_id'] . " ";
$result = mysqli_query($conn, $days);
$due_date = date('Y-m-d', strtotime($date_borrow. ' + $result days'));
if ($librarian_id == '') {
echo "librarian is empty";
}
else if ($member_id == '') {
echo "member id is empty";
}
else if ($book_id == '') {
echo "book is empty";
}
else if ($date_borrow == '') {
echo "date borrow is empty";
}
else if ($status_id == '') {
echo "status is empty";
}
else if ($due_date == '') {
echo "due date is empty";
}
else {
$sql = " INSERT INTO borrow_book (librarian_id, member_id,
book_id, date_borrow, due_date, status_id)
VALUES
('$librarian_id', '$member_id', '$book_id',
'$date_borrow', '$due_date', '$status_id' ) ";
if ($conn->query($sql) === TRUE)
{
$message = "Borrowing book successful";
echo "<script type='text/javascript'>alert('$message');</script>";
}
else
{
$message = "Borrowing book failed Failed";
echo "<script type='text/javascript'>alert('$message');</script>";
}
}
$conn->close();
?>
and this is my HTML code
<?php
include 'php/header.php';
require_once 'php/connect.php';
?>
<form method="POST" action="php/borrow.php">
<h1>Borrow Book</h1>
Transacted by:
<br>
<div>
<select name="librarian_id">
<option>Select Librarian
<?php
$sql = "SELECT * FROM librarian";
$result = mysqli_query($conn, $sql);
while ($row =mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['librarian_id'] ."'>"
. $row['Fname'] . " " . $row['Lname'] . "</option>";
}
?>
</option>
</select><br><br>
</div>
Select Member
<br>
<div>
<select name="member_id">
<option>Select member
<?php
$sql = "SELECT * FROM members";
$result = mysqli_query($conn, $sql);
while ($row =mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['member_id'] ."'>"
. $row['Fname'] . " " . $row['Lname'] . "</option>";
}
?>
</option>
</select><br><br>
</div>
<div>
<select name="book_id">
<option>Select a Book
<?php
$sql = "SELECT book_setup.book_id, book.book_id, book.title FROM book_setup
INNER JOIN book ON book_setup.book_id = book.book_id WHERE book_setup.status_id = '1' ";
$result = mysqli_query($conn, $sql);
while ($row =mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['book_id'] . "'>"
. $row['title'] . "</option>";
}
?>
</option>
</select><br><br>
</div>
Borrow Date:
<br><br>
<input name="date_borrow" value="<?php echo date('Y-m-d'); ?>" readonly>
<br><br>
Status:
<div>
<select name="status_id">
<option>
<?php
$sql = "SELECT * FROM borrower_status";
$result = mysqli_query($conn, $sql);
while ($row =mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['status_id'] ."'>"
. $row['status'] . "</option>";
}
?>
</option>
</select><br><br>
</div>
<br>
<br>
<button class="button" type="submit">Submit</button>
<button type="reset" value="Reset">Reset</button>
</form>
this is my database for borrowing book
and this is where I get the book that is available to borrow
Do this:
$res = mysqli_query($con, " SELECT days_id FROM book_setup WHERE book_id = '$book_id' ");
$days = mysqli_fetch_assoc($res)['days_id'];

Session variable and Dynamic Pagination in php

<form action='movies.php' method='POST'>
Language: <select name="language">
<option selected>hindi</option>
<?php
require("config.php");
$result="SELECT language FROM movies";
$q = mysqli_query($conn,$result) or die(mysql_error());
while ($row=mysqli_fetch_array($q)) {
$s1=$row["language"];
echo "<option>
$s1
</option>";
}
echo "<br>"
?>
</select>
<br /> <br />
<input type='submit' value='Submit' />
</form>
<?php
$lang=#$_POST['language'];
$_SESSION["lang1"]=$lang;
/*
if($lang){
$sql = "SELECT name,language FROM movies WHERE language='$lang'";
$result = mysqli_query($conn,$sql);
if (mysqli_num_rows($result)>0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo '<div class="query"> <img src="images\tiles\bb.jpg"> ';
echo "<h3> " . $row["name"]."</h3>". "<br>";
echo "</div>";
}
} else {
echo "0 results";
}
}
*/
$page=#$_GET['page'];
if($page==""|| $page=="1")
{
$page1=0;
}
else{
$page1=($page*3)-3;
}
$sql = "SELECT name,language FROM movies WHERE language='". $_SESSION['lang1']."' limit $page1,3 ";
$result = mysqli_query($conn,$sql);
$a= mysqli_num_rows($result);
while ($list=mysqli_fetch_array($result))
{
echo $list['name'] . " : " . $list['language'] . "<br />";
}
$sql = "SELECT name,language FROM movies WHERE language='$lang'";
$result = mysqli_query($conn,$sql);
$a= mysqli_num_rows($result);
$numrows=$a;
$rowsperpage=3;
$totalpages= ceil($numrows/$rowsperpage);
echo "</br>";
for($b=1;$b<=$totalpages;$b++)
{
?><?php echo $b." ";?> <?php
}
?>
I get proper output on movies.php which is the first 3 rows from database,but when i click on the dynamically created pagination link like movies.php?page=2 then there is no output on this page.This code works fine if i manually set the
$_SESSION["lang1"]="English"; then i get proper output but when i take input from the form it doesnt work.

Second form on a PHP page won't run

I have two forms on a page. When I run the first, it works as intended, but the second, despite having different form id and all the elements being named, will not (it attempts to run the first form, I think, but with no elements being posted it will return no result).
The second form is in the "Roles" section.
Here is the code - any help is appreciated!
/***** Section: Rights *****/
echo '
<!-- div: Edit -->
<div id="dashboardPanelWrapper">
<div id="sectionArrow"></div>
<div id="dashboardPanelTitle">User rights and privileges</div>
<div id="dashboardPanelContent">';
echo "<div id='DV_simple_wrapper_wide'>";
echo "<table width='60%'><tr><th>Role</th><th>Staff</th><tr>";
$query = "SELECT DISTINCT rightName FROM ".$dbName.".rights WHERE siteLimit='gpvwc' AND rightName!='ADMIN' ORDER BY rightName ASC";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result)) {
$role=$row[0];
echo "<tr><td>$role</td><td>";
// $query2= "SELECT userId FROM ".$dbName.".rights WHERE rightName='$role' AND siteLimit='gpvwc'";
$query2 = "SELECT CONCAT (u.firstName, ' ',u.lastName) AS username, r.head FROM ".$dbName.".rights r LEFT JOIN ".$dbName.".users u ON r.userId=u.id WHERE r.rightName='$role' AND r.siteLimit='gpvwc' ORDER BY r.head DESC, username ASC";
$result2 = mysql_query($query2);
while ($row = mysql_fetch_row($result2)) {
$name=$row[0];
$head=$row[1];
if ($head=='1') { $name="<b>$name, </b>"; }
if ($head=='0') { $name="$name, "; }
echo "$name";
}
echo "</td></tr>";
}
echo "</table>";
echo "<form id='1' action='' method='post'>";
$usersAsArray = $user->listUsers($banned=false);
echo '<div id="defButtonWrapperH">';
echo '<select id="DriverAppealEvent" class="defSelectV" style="min-width: 70px; margin-bottom: 10px;" onchange="submitTarget(this.value);">';
echo '<option value="0">--</option>';
foreach ($usersAsArray as $key => $value) {
echo '<option value="'.$key.'"';
if (isset($target) && $target == $key)
echo 'selected';
echo '>'.$value.'</option>';
}
echo '</select>';
echo '</div>';
echo '<p> </p>';
echo '<p> </p>';
$userToEdit = false;
if ($target) {
$userToEdit = $user->userToView($target);
// Check if any rights given for this user and update form if any
$query = "SELECT u.*, r.rightName, r.countryLimit, r.siteLimit, r.isActive, r.head FROM ".$dbName.".users u
LEFT JOIN ".$dbName.".rights r ON r.userId=u.id WHERE u.id=".$target;
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
if ($row['rightName'] != '') {
$userToEdit['rights'][] = array(
'rightName' => $row['rightName'],
'rightCountryLimit' => $row['countryLimit'],
'rightSiteLimit' => $row['siteLimit'],
'rightIsActive' => $row['isActive'],
'rightHead' => $row['head']
);
}
}
mysql_free_result($result);
// If the user has rights then write a table with all them plus options to revoke
if (!empty($userToEdit['rights'])) {
drawUserRightsTable($userToEdit);
}
echo "</form>";
// Draw selector with rights here so we can add new rights to this user
$useradd=$userToEdit['id'];
echo "<form id='addadmin' action='$RKP/kernel/lib/php_lib/action/AC_Admins.php?op=add&user=$useradd' method='post'>";
echo "Role: <select name='role'>";
$query = "SELECT DISTINCT rightName FROM ".$dbName.".rights WHERE rightName!='ADMIN' ORDER BY rightName ASC";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result)) {
$righttoadd=$row[0];
echo "<option value='$righttoadd'>$righttoadd</option>";
}
echo "</select></br>";
echo "Head: <input type='radio' name='head' value='0' checked> No <input type='radio' name='head' value='1'> Yes";
echo "<p> </p>";
MODW_Buttons_Button(Normal,Normal,Normal,Normal,None,$RKP,$id,BGenSu,$intern,$intcont);
echo "</form>";
//echo '<pre>';print_r($userToEdit);echo '</pre>';
}
echo "</div>";
echo ' </div>
</div>';
/***** Section: Roles *****/
echo '
<!-- div: Edit -->
<div id="dashboardPanelWrapper">
<div id="sectionArrow"></div>
<div id="dashboardPanelTitle">Disciplinary Committee Roles</div>
<div id="dashboardPanelContent">';
echo "<div id='DV_simple_wrapper_wide'>";
echo "<table width='60%'><tr><th>Series</th><th>Staff</th><th> </th><tr>";
$query = "SELECT id, compName FROM ".$dbName.".competitions WHERE active='1' AND id!='10' ORDER BY id ASC";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result)) {
$compid=$row[0];
$compName=$row[1];
echo "<tr><td><b>$compName</b></td><td>";
// $query2= "SELECT userId FROM ".$dbName.".rights WHERE rightName='$role' AND siteLimit='gpvwc'";
$query2 = "SELECT CONCAT (u.firstName, ' ',u.lastName) AS username, r.role, u.id, r.series FROM ".$dbName.".DC_roles r LEFT JOIN ".$dbName.".users u ON r.user=u.id WHERE r.series='$compid' ORDER BY username ASC";
$result2 = mysql_query($query2);
while ($row = mysql_fetch_row($result2)) {
$name=$row[0];
$role=$row[1];
$userid=$row[2];
$seriesid=$row[3];
if ($role=='1') { $name="<i>$name</i>"; }
if ($role=='0') { $name="$name"; }
echo "$name <a href='$RKP/kernel/lib/php_lib/action/AC_Admins.php?op=DelDCRights&user=$userid&comp_id=$seriesid'><b>X</b></a></br>";
}
echo "</td></tr>";
}
echo "</table>";
echo "</div>";
echo "<form id='dcroles' action='$RKP/kernel/lib/php_lib/action/AC_Admins.php?op=AddDCRights' method='post'>";
echo "User: <select id='userDC' name='userDC'>";
$query1 = "SELECT id, firstName, lastName FROM ".$dbName.".users ORDER BY lastName ASC, firstName ASC";
$result1 = mysql_query($query1);
while ($row = mysql_fetch_row($result1)) {
$DCuserId=$row[0];
$DCfirstName=$row[1];
$DClastName=$row[2];
echo "<option value='$DCuserId'>$DClastName, $DCfirstName</option>";
}
echo "</select></br>";
echo "</br>";
echo "Series: <select id='seriesDC' name='seriesDC'>";
$query = "SELECT id, compName FROM ".$dbName.".competitions WHERE active='1' AND id!='10' ORDER BY id ASC";
$result = mysql_query($query);
while ($row = mysql_fetch_row($result)) {
$DCcompId=$row[0];
$DCcompName=$row[1];
echo "<option value='$DCcompId'>$DCcompName</option>";
}
echo "</select></br>";
echo "Third Checker: <input type='radio' id='head' name='head' value='0' checked> No <input type='radio' name='head' value='1'> Yes</br>";
echo "<input type='submit' value='Submit'>";
echo "</form>";

How do I reduce the number of variables and connections for php connecting to mysql server?

I am trying to reduce the number of connections that this page makes. Everything I read says that only one connection should be enough however if I remove the additional connections the page doesn't connect to my server and provide me the results I am looking for. Also one of the queries I am using twice but if I call the original query the second time it also does not work.
What am I doing wrong?
<?php
$dbaddress="localhost";
$dbuser="testuser";
$dbpass="testpass";
$dbname="testdb";
$dbtable="elo";
$query="SELECT Sequnce, mcacctname FROM `elo`;";
$con=mysqli_connect($dbaddress,$dbuser,$dbpass,$dbname);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysql_connect($dbaddress, $dbuser, $dbpass);
mysql_select_db($dbname);
$sql = "SELECT Sequence, mcacctname FROM `elo`;";
$result = mysql_query($sql);
mysql_connect($dbaddress, $dbuser, $dbpass);
mysql_select_db($dbname);
$sql2 = "SELECT Sequence, mcacctname FROM `elo`;";
$result2 = mysql_query($sql2);
$sqlstart = "SELECT mcacctname, elo FROM `elo`;";
$q = mysql_query($sqlstart);
?>
<form name="player1" method="post" action="predictions.php">
<label for="Select Player 1">Select Player 1:
<?php
echo "<select name='elouser1'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['Sequence'] . "'>" . $row['mcacctname'] . "</option>";
}
echo "</select>";
?>
</label>
<input type="submit" value="Player 1 Wins">
</form>
<br>
<form name="player2" method="post" action="predictions.php">
<label for="Select Player 2">Select Player 2:
<?php
echo "<select name='elouser2'>";
while ($row2 = mysql_fetch_array($result2)) {
echo "<option value='" . $row2['Sequence'] . "'>" . $row2['mcacctname'] . "</option>";
}
echo "</select>";
?>
</label>
<input type="submit" value="Player 2 Wins">
</form>
<table>
<tr>
<?
echo '<div class="container">';
while($res = mysql_fetch_array($q)){
echo '<tr><td><div class="item">'. $res['mcacctname'] . '</td><td>' . $res ['elo'] . '</div></td></tr>';
}
echo '</div>';
mysqli_close($con);
?>
</tr>
</table>
Once a connection is open in a page you don't need to re-open it for each query. You can simply remove all the statements that create a connection and select the database, except the first one.
Note you're using mysqli to open the connection, but mysql to query it. The two sets of functions are not interchangeable: use mysqli as 'mysql' is deprecated and support will be removed in the future.
Try this:
$dbaddress="localhost";
$dbuser="testuser";
$dbpass="testpass";
$dbname="testdb";
$dbtable="elo";
$query="SELECT Sequence, mcacctname FROM `elo`;";
$con=mysqli_connect($dbaddress,$dbuser,$dbpass,$dbname);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT Sequence, mcacctname FROM `elo`;";
$result = mysqli_query($con,$sql) or die(mysqli_error($con));
$sql2 = "SELECT Sequence, mcacctname FROM `elo`;";
$result2 = mysqli_query($con,$sql2) or die(mysqli_error($con));
$sqlstart = "SELECT mcacctname, elo FROM `elo`;";
$q = mysqli_query($con, $sqlstart) or die(mysqli_error($con));
?>
<form name="player1" method="post" action="predictions.php">
<label for="Select Player 1">Select Player 1:
<?php
echo "<select name='elouser1'>";
while ($row = mysqli_fetch_array($result)) {
echo "<option value='" . $row['Sequence'] . "'>" . $row['mcacctname'] . "</option>";
}
echo "</select>";
?>
</label>
<input type="submit" value="Player 1 Wins">
</form>
<br>
<form name="player2" method="post" action="predictions.php">
<label for="Select Player 2">Select Player 2:
<?php
echo "<select name='elouser2'>";
while ($row2 = mysqli_fetch_array($result2)) {
echo "<option value='" . $row2['Sequence'] . "'>" . $row2['mcacctname'] . "</option>";
}
echo "</select>";
?>
</label>
<input type="submit" value="Player 2 Wins">
</form>
<table>
<tr>
<?
echo '<div class="container">';
while($res = mysqli_fetch_array($q)){
echo '<tr><td><div class="item">'. $res['mcacctname'] . '</td><td>' . $res ['elo'] . '</div></td></tr>';
}
echo '</div>';
mysqli_close($con);
?>
</tr>
</table>

How to use arrays for form input and update respective database records

I'm new to PHP... I want to know how to populate a form from mySQL. I'm stumped at the input section where I am trying to allow the user to select choices for radio button /checkbox for each record. thanks in advance for anyone's help!
TC
Here's a snippet of my code:
<?php
$mQuantity = 1;
$con = mysql_connect("localhost","t","c");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("tc", $con);
/*
if request.form("itemname")<>" " then
cSQLAcct = "SELECT * FROM Restaurant_Menus WHERE Restaurant_ID='" & mRestaurant_ID & "' and Item like '%" & Request.Form("ITEMNAME") & "%' ORDER BY FOODTYPE, ITEM"
else
cSQLAcct = "SELECT * FROM Restaurant_Menus WHERE Restaurant_ID='" & mRestaurant_ID & "' ORDER BY FOODTYPE, ITEM"
end if
*/
// retrieve form data
$input = $_POST['itemname'];
echo $_POST['ITEM'];
$mItem = $_POST['ITEM'];
$mPrice = $_POST['PRICE'];
$mQuantity = $_POST['QUANTITY'];
$mOrderTotal = 0;
$mSide0 = '1';
$mOil = '1';
$mStarch = '1';
$mSalt = '1';
// use it
echo "You searched for: <i>$input</i>";
echo $mSessionID;
mysql_query("INSERT INTO OrderQueue (SessionID,item,quantity,price,no_oil,no_starch,no_salt,side0) VALUES ('$mSessionID','$mItem','$mQuantity','$mPrice','$mOil','$mStarch','$mSalt','$mSide0')");
/*
$sql="SELECT * FROM Restaurant_Menus
WHERE
Item like '%$input%'";
*/
$sql="SELECT * FROM OrderQueue
WHERE
SessionID = '$mSessionID'";
$result = mysql_query($sql);
//('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
//echo $input;
//echo $sql;
/*
if ($input!=" "){
$result = mysql_query($sql);
}
// cSQLAcct = "SELECT * FROM Restaurant_Menus WHERE Restaurant_ID='" & mRestaurant_ID & "' and Item like '%" & Request.Form("ITEMNAME") & "%' ORDER BY
else
{ $result = mysql_query("SELECT * FROM Restaurant_Menus");
}
*/
$c=1;
$class[1] = 'odd';
$class[2] = '';
$array_no_oil = array();
$array_no_salt = array();
$array_no_starch = array();
$array_rice = array();
echo "<table border='1' width=500px>
<tr>
<th></th>
<th align=left>Item</th>
<th align=right>Price</th>
<th align=right>Quantity</th>
</tr>";
//<tr onMouseOver="this.bgColor = '#F3EB49'" onMouseOut ="this.bgColor = '#DDDDDD'" bgcolor="#DDDDDD">
while($row = mysql_fetch_array($result))
{
//echo '<tr class="'.$class[$c].'" onMouseOver='#F3EB49' onMouseOut ='#DDDDDD' bgcolor="#DDDDDD" >';
//echo "<tr class='odd'>";
//echo '<tr onMouseOver="this.bgColor = '#F3EB49'" onMouseOut ="this.bgColor = '#DDDDDD'" bgcolor="#DDDDDD">'
?>
<TR onMouseover="this.bgColor='#FFC000'"onMouseout="this.bgColor='#DDDDDD'">
<?php
/*
<form action="Orders.asp" method="post" target="_top" name="LogonForm">
<td><font size = 2>
<!--<%= mQuantity %>-->
<INPUT TYPE="TEXT" NAME="QUAN" VALUE="1" SIZE=2>
</font></td>
<td width=50px><font size = 2>
<INPUT TYPE=HIDDEN NAME=ITEM VALUE="<% =mItem %>">
<INPUT TYPE=HIDDEN NAME=PRICE VALUE=<% =mPrice %>>
<INPUT TYPE=HIDDEN NAME=RID VALUE= <% =mRestaurant_ID %>>
<INPUT TYPE=HIDDEN NAME=ADDITEM VALUE = "1">
<input id="Choices" class="findit" type="submit" value ="Order" />
</form>
*/
?>
<?php
// Obtain list of images from directory
//$img = getRandomFromArray($imgList);
}
?>
<?php
if ($row['Picture']!=" "){
echo "<td><a><img src='images/".$row['Picture'].".JPG' height=50px></a></td>";
}
else{
echo "<td></td>";
}
echo "<td width=200><b>" . $row['Item'] . "</b><br>
<input class='dropwidth' type='radio' name='$array_rice' value='1' selected>White Rice<br>
<input type='radio' name='$array_rice' value='2'>Pork Fried Rice<br>
<input type='radio' name='$array_rice' value='3'>Brown Rice<br>
<input type='checkbox' name='$array_no_oil' value='1' />No Oil
<input type='checkbox' name='starch' value='no oil' />No Starch
<input type='checkbox' name='salt' value='no salt' />No Salt
</td>";
echo "<td width=50 align=right>" . number_format($row['Price'],2) . "</td>";
$mQuantity = "'" . number_format($row['Quantity'],0) . "'";
$mPrice = "'" . number_format($row['Price'],2) . "'";
$mLineItemTotal = $row['Quantity'] * $row['Price'];
$mOrderTotal = (number_format($mOrderTotal,2) + number_format($mLineItemTotal,2));
echo $mOrderTotal;
$mLineItemTotal2 = "'". number_format($mLineItemTotal,2) . "'";
//echo "<td>" . $mQuantity. "</td>";
?>
<form action="orders.php" method="post" target="_top" name="LogonForm">
<td width="50" align=right><font size = 2>
<!--<%= mQuantity %>-->
<!--<INPUT TYPE="TEXT" NAME="QUANTITY" VALUE=<?php $mQuantity; ?>>-->
<INPUT TYPE="TEXT" NAME="QUANTITY" VALUE=<?php echo $mQuantity.";" ?>/>
</font></td>
<?php echo "<td width=50 align=right>" . $mLineItemTotal . "</td>";?>
<!--<td width=50px><font size = 2>-->
<!--<INPUT TYPE="TEXT" NAME="LINEITEMTOTAL" VALUE=<?php echo $mLineItemTotal.";" ?> WIDTH=10/>-->
<INPUT TYPE=HIDDEN NAME=ITEM VALUE=<?php $mItem ?> />
<INPUT TYPE=HIDDEN NAME=PRICE VALUE=<?php $mPrice ?>/>
<INPUT TYPE=HIDDEN NAME=RID VALUE=<?php $mRestaurant_ID ?>/>
<INPUT TYPE=HIDDEN NAME=ADDITEM VALUE = "1">
<!--<input id="Choices" class="findit" type="submit" value ="Order" />-->
</form>
<?php
echo "</tr>";
if($c==2) $c=0;
$c++;
}
echo "</table>";
echo "<div>".$mOrderTotal."</div>";
mysql_close($con);
?>
You should name your HTML form elements as such: MyElement[] when using them as arrays. For example:
<form method="post" name="myForm" action="myForm.php">
<select multiple name="myFormSelectMultiple[]">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</form>
In this select multiple example, when the first two items are selected and then posted this form would produce similar output to the following:
array('myFormSelectMultiple' => array(1,2));
Hope this helps!

Categories