How to put radio button inside the status, 2 radio buttons (approved and disapproved) and the checked radio button will be save in database as well under status field.
This is my codes.. patient[6] is the status
$sql = "select patientid, firstname, lastname, gender, patienttype, philhealth, status from patients where lastname LIKE '%" . $_POST["key"] . "%' or philhealth LIKE '%" . $_POST["key"] . "%' ";
$result = mysql_query($sql, $connection);
$rownum = 0;
$bgcolor = "";
while($patient = mysql_fetch_array($result))
{
$rownum += 1;
if($rownum == 2)
{
$bgcolor = "#FFF";
$rownum = 0;
}
else
{ $bgcolor = "#f9f9f9"; }
$approved_checked = $patient[6] == 'Approved' ? 'checked' : '';
echo "
<tr id='" . $patient[0] . "' style='background: " . $bgcolor . "' onclick='openphilhealthapproval() '>
<td id='td27_cell1' style='height: 25px;'>" . $patient[5] . " </td>
<td id='td27_cell2' style='height: 25px;'>" . $patient[0] . "</td>
<td id='td27_cell3' style='height: 25px;'>" . $patient[1] . " " . $patient[2] . "</td>
<td id='td27_cell4' style='height: 25px;'>" . $patient[3] . "</td>
<td id='td27_cell5' style='height: 25px;'>" . $patient[4] . "</td>
<td id='td27_cell6' style='height: 25px;'>" . $patient[6] . "</td>
</tr>
";
}
You should put the content of this TD element into your status TD element. Also you need to replace ***patientID*** signs with the patientID when you build your HTML. You could see the working example here.
<td>
<input type="radio" name="statusradio***patientID***" value="approved" id="approvedradio***patientID***"/>
<label for="approvedradio***patientID***">approved</label>
<input type="radio" name="statusradio***patientID***" value="disapproved" id="disapprovedradio***patientID***"/>
<label for="disapprovedradio***patientID***">disapproved</label>
</td>
Related
This is what I have currently (which doesn't do anything)
<input type="text" id="search" " placeholder="Search..">
<table id='table'>
<!-- INVENTORY TABLE -->
<?php
$query = "SELECT * FROM StatesboroSwitchActive";
$result = mysqli_query($db, $query);
$count = 0;
echo "
<tr>
<th></th>
<th></th>
<th>Name</th>
<th>Model</th>
<th>Serial</th>
<th>MAC</th>
<th>Type</th>
<th>Notes</th>
<th>Cisco Notes</th>
<th>Location</th>
</tr>";
while ($row = mysqli_fetch_array($result)) {
$count++;
echo "<tr><td>" . "<button id='delete'>RMA</button>" .
"</td><td>" . "<button id='modify'>Modify</button>" .
"</td><td>" . $row['Name'] .
"</td><td>" . $row['Model'] .
"</td><td>" . $row['Serial'] .
"</td><td>" . $row['MAC'] .
"</td><td>" . $row['Type'] .
"</td><td>" . $row['Notes'] .
"</td><td>" . $row['Cisco Notes'] .
"</td><td>" . $row['Location'] . "</td></tr>";
}
echo "<h3>Total: " . $count . "</h3>";
?>
I want to be able to use the search box to make this table filter down into what is typed by the user. I am pretty lost right now
It's all depends on all of your row names on your SQL. Suppose that yours were Name, Model, Serial, MAC, Type, Notes, and Cisco_Notes, Location. So you can add one submit button to apply those search arguments. Then, you can add some filter from SQL, e.g.
SELECT * FROM StatesboroSwitchActive
WHERE Name LIKE '%something%'
OR Model LIKE '%something%'
OR Serial LIKE '%something%'
...
The rest doesn't need to be changed. Please correct me if I'm wrong.
<form action="" method="post">
<input type="text" name="search" id="search" " placeholder="Search.."/>
<input type="submit" value="Submit" />
</form>
<?php
$search = '%' . mysqli_real_escape_string($db, $_REQUEST['search']) . '%';
$query = "SELECT * FROM StatesboroSwitchActive
WHERE Name LIKE '$search'
OR Model LIKE '$search'
OR Serial LIKE '$search'
OR MAC LIKE '$search'
OR Type LIKE '$search'
OR Notes LIKE '$search'
OR Cisco_Notes LIKE '$search'
OR Location LIKE '$search'";
$result = mysqli_query($db, $query);
$count = 0;
echo "
<tr>
<th></th>
<th></th>
<th>Name</th>
<th>Model</th>
<th>Serial</th>
<th>MAC</th>
<th>Type</th>
<th>Notes</th>
<th>Cisco Notes</th>
<th>Location</th>
</tr>";
while ($row = mysqli_fetch_array($result)) {
$count++;
echo "<tr><td>" . "<button id='delete'>RMA</button>" .
"</td><td>" . "<button id='modify'>Modify</button>" .
"</td><td>" . $row['Name'] .
"</td><td>" . $row['Model'] .
"</td><td>" . $row['Serial'] .
"</td><td>" . $row['MAC'] .
"</td><td>" . $row['Type'] .
"</td><td>" . $row['Notes'] .
"</td><td>" . $row['Cisco Notes'] .
"</td><td>" . $row['Location'] . "</td></tr>";
}
echo "<h3>Total: " . $count . "</h3>";
inspired from : Creating a search form in PHP to search a database?
Here's what I'm trying to do:
I'm working on an inventory management system for my work, and the idea is that when we need to order something it's status is set to 'order' in the mySQL database which contains all of our inventory items. We have an 'Order Queue' page that displays all of the things that need ordered. The twist is that we need two different tables for each supplier: one for Purchase Orders and one for Request for Quotes (e.g. buying raw material isn't always a constant price, so a PO and RFQ need a different format). Then for each supplier table there is a submit button that says "Push supplier name PO/RFQ".
Pressing this button takes you to a second page which creates the PO and sends the email to the supplier. I know this isn't the issue here because regardless of what is in this script it will run three times when the button is pressed.
Here's some code:
$suppTable = mysqli_query($conn,"SELECT * FROM `suppliers` WHERE (`user` = '" . $user_login . "')");
This creates the array storing all the supplier info, and is all correct.
<div class="trackheader" style="border-radius:5px 5px 0px 0px; border: 2px solid #CC3333;">
<h3 style="color:white !important; margin-left: 10px; vertical-align: middle; display: inline-block;">Display:</h3>
</div>
<div class="trackcont3" style="border-radius:0px 0px 5px 5px; border: 2px solid #CC3333; margin-bottom:20px;">
<form action="" method="POST" id="rec">
<?php
while($row1 = mysqli_fetch_assoc($suppTable)){
echo "<input type='checkbox' id='" . $row1['name'] . "' name='" . $row1['name'] . "' value='" . $row1['name'] . "' onchange='this.form.submit()'";
if(isset($_POST['' . $row1['name'] . ''])){
echo "checked='checked'";
}
echo ">";
echo "<label for='" . $row1['name'] . "'>" . $row1['name'] . "</label>";
}
?>
</form>
</div>
Please ignore the inline CSS - this will get added to the stylesheet once this actually works...
This is a pretty straightforward snippet: it creates display toggles for each supplier in the database so that they don't all show up at once.
Now for the fun stuff:
<?php
$loopTable = mysqli_query($conn,"SELECT * FROM `suppliers` WHERE (`user` = '" . $user_login . "')"); //this creates another array with each supplier tied to the user account
while($row2 = mysqli_fetch_assoc($loopTable)){ //this while loop creates two tables for each supplier: one with items that need to be ordered in a PO and another table for RFQ
if(isset($_POST['' . $row2['name'] . ''])){ //controls display from the above form
$display['' . $row2['name'] . ''] = "block";
} else {
$display['' . $row2['name'] . ''] = "none";
}
echo "<div style='display:" . $display['' . $row2['name'] . ''] . " ;'>";
echo "<div class='trackheader' style='border-radius:5px 5px 0px 0px; border: 2px solid #CC3333;'>
<h3 style='color:white !important; margin-left: 10px; vertical-align: middle; display: inline-block;'>" . $row2['name'] . " PO</h3>
</div>";
echo "<div class='trackcont2'><table style='width:100%; !important'><tbody style='width:100%; !important'>
<tr style='width:100% !important;'>
<th style='width:16.6%;'><h3 style='color:grey !important;'>ALEX ID</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Description</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Supplier P/N</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Order QTY</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Price</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Total</th>
</tr>";
$i = 0;
$listTablePO = mysqli_query($conn,"SELECT * FROM `inventory` WHERE (`user` = '" . $user_login . "') AND (`supplier` = '" . $row2['name'] . "') AND (`status` = 'order') AND (`method` = 'PO')"); //this creates an array with all database items from the appropriate supplier which need ordered (and go in the PO table)
$total = 0; //tallies a running total of the price
while($row3 = mysqli_fetch_assoc($listTablePO)){ //this while loop creates the table of all parts that need ordered and their necessary info
if($i % 2 == 0){
echo "<tr class='odd' style='text-align: center;'>";
} else {
echo "<tr class='even' style='text-align: center;'>";
}
echo "<td>" . $row3['part_name'] . "</td>";
echo "<td>" . $row3['description'] . "</td>";
if($row3['order_link'] == null){
echo "<td>" . $row3['supplier_part_no'] . "</td>";
} else {
echo "<td><a href='" . $row3['order_link'] . "' target='_blank'>" . $row3['supplier_part_no'] . "</a></td>";
}
if($row['order_override'] == 0){
echo "<td>" . $row3['order_qty'] . "</td>";
$qty = $row3['order_qty'];
} else {
echo "<td>" . $row3['order_override'] . "</td>";
$qty = $row3['order_override'];
}
echo "<td>$" . sprintf('%.2lf', $row3['price']) . "</td>";
$total = ($total + ($qty * $row3['price']));
echo "<td>$" . sprintf('%.2lf', $total) . "</td>";
echo "</tr>";
$i++;
}
echo "</tbody></table></div>
<form action='/po-mailing/' method='POST' name='" . $row2['name'] ."PO'>
<input type='hidden' value='" . $row2['name'] . "' name='PO' id='PO'></input>
<button type='submit' class='addbutton' style='margin-top: -20px !important; margin-bottom: 20px;'>Push " . $row2['name'] . " PO</button>
</form>
</div>"; //the above snippet handles creating the appropriate form and submit button. All this needs to do is route to the appropriate page (/po-mailing/) and pass the correct supplier name.
//From there I can get all the necessary info from the SQL database and don't need to pass any other info through the form.
//I suspect this is where my issue lies, but all I need is an individual Push PO button for each supplier that directs to /po-mailing/ and passes the supplier info to the page. The problem here is it is doing it three times...
The next code is basically the same as above but for the RFQ table. Skip this part
// the same code is essentially repeated for RFQ for each supplier with minor format changes (it is also irrelevant as I have only been testing with the PO side)
echo "<div style='display:" . $display['' . $row2['name'] . ''] . " ;'>";
echo "<div class='trackheader' style='border-radius:5px 5px 0px 0px; border: 2px solid #CC3333;'>
<h3 style='color:white !important; margin-left: 10px; vertical-align: middle; display: inline-block;'>" . $row2['name'] . " RFQ</h3>
</div>";
echo "<div class='trackcont2'><table style='width:100% !important;'><tbody style='width:100%; !important'>
<tr style='width:100% !important;'>
<th style='width:16.6%;'><h3 style='color:grey !important;'>ALEX ID</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Description</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Supplier P/N</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Order QTY</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Last Price</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Estimate</th>
</tr>";
$i = 0;
$listTableRFQ = mysqli_query($conn,"SELECT * FROM `inventory` WHERE (`user` = '" . $user_login . "') AND (`supplier` = '" . $row2['name'] . "') AND (`status` = 'order') AND (`method` = 'RFQ')");
while($row5 = mysqli_fetch_assoc($listTableRFQ)){
if($i % 2 == 0){
echo "<tr class='odd' style='text-align: center;'>";
} else {
echo "<tr class='even' style='text-align: center;'>";
}
echo "<td>" . $row5['part_name'] . "</td>";
echo "<td>" . $row5['description'] . "</td>";
if($row5['order_link'] == null){
echo "<td>" . $row5['supplier_part_no'] . "</td>";
} else {
echo "<td><a href='" . $row5['order_link'] . "' target='_blank'>" . $row5['supplier_part_no'] . "</a></td>";
}
if($row['order_override'] == 0){
echo "<td>" . $row5['order_qty'] . "</td>";
$qty = $row5['order_qty'];
} else {
echo "<td>" . $row5['order_override'] . "</td>";
$qty = $row5['order_override'];
}
echo "<td>$" . sprintf('%.2lf', $row5['price']) . "</td>";
$total = ($total + ($qty * $row5['last_price']));
echo "<td>$" . sprintf('%.2lf', $total) . "</td>";
echo "</tr>";
$i++;
}
echo "</tbody></table></div>
<form action='/rfq-mailing/' method='POST' id='" . $row2['name'] ."RFQ'>
<input type='hidden' value='" . $row2['name'] . "' name='" . $row2['name'] . "' id='" . $row2['name'] . "'></input>
<button type='submit' class='addbutton' style='margin-top: -20px !important; margin-bottom: 20px;'>Push " . $row2['name'] . " RFQ</button>
</form>
</div>";
}
?>
Hopefully someone can spot where I'm screwing up.. FWIW I'm also using Wordpress as a backend for the system (just an easy way to handle accounts, create pages, etc)
I found the solution:
My wordpress theme appears to load the head of each page multiple times, so the issue wasn't with the code itself. On each load it was submitting the info.
Encasing necessary info in if(isset($_POST['submitbuttonexample'])){} fixed the issue.
Hey guys i have a problem, there is a page where i need to display data acording to date, but from 2 databases and from 2 tables from each databases,
1 Database name = highmob_comenzi Tables = players and vanzari
2 Database name = highmob_comenzi2 Tables = players and vanzari
this is the code what i got , i have tryed "select * from players, vanzari" but still no luck, even that wont extract data from both databases :(
<table class='table table-responsive-sm table-bordered table-striped table- sm' border="2px">
<thead>
<tr>
<th>Locatia Vanzari</th>
<th>Tip. Cert.</th>
<th>Nr.</th>
<th>Status Comanda Mobila</th>
<th>Status Comanda Tapiterii</th>
<th>Status Livrare</th>
<th>Ora Livrare</th>
<th>Detalii Comanda</th>
<th>Total</th>
<th>Avans</th>
<th>Rest</th>
<th></th>
</tr>
<?php
$servername = "localhost";
$username = "id";
$password = "pw";
$dbname = "highmob_comenzi2";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = ("select *
from highmob_comenzi.players
cross join highmob_comenzi.vanzari
union all
select *
from highmob_comenzi2.players
cross join highmob_comenzi2.vanzari
WHERE statuslivrare >= CURRENT_DATE()");
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "
</thead>
<tbody>
<tr>
<td>HERE DATABASE NAME</td>
<td><a href='vezibilettransportcomenzi.php?id=" . $row["id"] . "' target='_blank' class='btn btn-sm btn-warning'>Tip. Cert.</a></td>
<td>" . $row["id"] . "</td>
<td>
" . $row["statuscomanda"] . "
</td>
<td>" . $row["statuscomandatapiterii"] . "</td>
<td>" . $row["statuslivrare"] . "</td>
<td>" . $row["oralivrare"] . "</td>
<td>" . $row["detaliicomanda"] . "</td>
<td>
" . $row["totaldeplata"] . "</td>
<td>" . $row["avans"] . " <br><a style='color:red;'>" . $row["banipreluati"] . "</a></td>
<td>" . $row["restdeplata"] . "<br><a style='color:red;'>" . $row["banipreluatirest"] . "</a></td>
<td><a href='edit.php?id=" . $row["id"] . "' target='_blank' class='btn btn-sm btn-primary' >Vezi comanda</a></td>
</tr>
";
}
} else {
echo "Nu sunt transporturi!";
}
$conn->close();
?>
</tbody>
</table>
you can access to the table in the same query without problem eg (assuming the tables have the same struct in both the database):
select *
from highmob_comenzi.players
cross join highmob_comenzi.vanzari
union all
select *
from highmob_comenzi2.players
cross join highmob_comenzi2.vanzari
this is only a sample for accessing to the 2 database in a single query. you must rethink the query with you join and condition
but based on you comment seem you need just (assuming that statuslivrare is a colum of the vanzari table)
select *
from highmob_comenzi.players
cross join highmob_comenzi.vanzari
WHERE vanzari.statuslivrare >= CURDATE()");
<?php
$servername = "localhost";
$username = "ID";
$password = "PW";
$dbname1 = "highmob_comenzi2";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname1 );
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = ("select * from highmob_comenzi2.players cross join highmob_comenzi2.vanzari
");
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "
</thead>
<tbody>
<tr>
<td>HERE DATABASE NAME</td>
<td><a href='vezibilettransportcomenzi.php?id=" . $row["id"] . "' target='_blank' class='btn btn-sm btn-warning'>Tip. Cert.</a></td>
<td>" . $row["id"] . "</td>
<td>
" . $row["statuscomanda"] . "
</td>
<td>" . $row["statuscomandatapiterii"] . "</td>
<td>" . $row["statuslivrare"] . "</td>
<td>" . $row["oralivrare"] . "</td>
<td>" . $row["detaliicomanda"] . "</td>
<td>
" . $row["totaldeplata"] . "</td>
<td>" . $row["avans"] . " <br><a style='color:red;'>" . $row["banipreluati"] . "</a></td>
<td>" . $row["restdeplata"] . "<br><a style='color:red;'>" . $row["banipreluatirest"] . "</a></td>
<td><a href='edit.php?id=" . $row["id"] . "' target='_blank' class='btn btn-sm btn-primary' >Vezi comanda</a></td>
</tr>
";
}
} else {
echo "Nu sunt transporturi!";
}
$conn->close();
?>
This is what i got and its working, it displays data from 1 database nammed highmob_comenzi2 and tables players and vanzari, but im getting alot of duplicates on display and also i need to insert a WHERE clause :
WHERE statuslivrare >= CURRENT_DATE()
any ideea?
I am new to HTML5 and PHP, I am trying to output a specific value in table data, If the database-retrieved-value is per condition.
My code:
<table class="scroll">
<thead style="background-color: #99E1D9; color: #705D56;">
<tr>
<th>ID</th>
<th>Name Client</th>
<th>Last Update</th>
<th style="padding-left: 30%;">Status</th>
</tr>
</thead>
<tbody id="hoverTable">
<?php
$connection = mysql_connect('localhost', 'root', '');
mysql_select_db('patientdb');
$query = "SELECT id, name, date FROM clients";
$result = mysql_query($query);
//status waarden uit
$status = "SELECT status FROM clients";
$status_ = mysql_query($status);
while($row = mysql_fetch_array($result)){ //Loop through results
echo "<tr>
<td>" . $row['id'] . "</td>
<td>" . $row['name'] . "</td>
<td>" . $row['date'] . "</td>
<td style='padding-left: 30%;'>" .
if ($status_ > 60){echo "red";
} elseif ($status_ > 50){echo "yellow";
} else{echo "green";}
. "</td>
</tr>";
}
mysql_close();
?>
</tbody>
</table>
Error output
Parse error: syntax error, unexpected T_IF in
/test/composition/login/portal/portal.php
on line 204
What is the right way to solve this?
EDIT
my current code:
<table class="scroll">
<thead style="background-color: #99E1D9; color: #705D56;">
<tr>
<th>Naam Client</th>
<th>Laatste Update</th>
<th style="margin-left: 40%; padding-left: 0%;">Status</th>
</tr>
</thead>
<tbody id="hoverTable" style="font-size: 11pt;">
<?php
$connection = mysql_connect('localhost', 'root', '');
mysql_select_db('patientdb');
$query = "SELECT id, naam, datum FROM clients";
$result = mysql_query($query);
$query2 = "SELECT status FROM clients";
$result2 = mysql_query($query2);
if (!empty ($result2)) {
while ($row2 = mysql_fetch_assoc($result2)) {
echo $row2['status'] . "<br />";
}
}
while($row = mysql_fetch_array($result)){ //Loop through results
echo "<tr>
<td>" . $row['id'] . "</td>
<td>" . $row['naam'] . "</td>
<td>" . $row['datum'] . "</td>
<td style='padding-left: 30%;'>";
if ($results2 > 60 && $results2 < 70) {
echo "red";
} elseif ($results2 > 50 && $results2 < 60) {
echo "yellow";
} else {
echo "green";
}
echo "</td>
</tr>";
}
mysql_close();
?>
</tbody>
</table>
Output the right data. but partly outside and partly inside the table.
You will have to remove the if statement out of the echo to get rid of the error Try this:
<table class="scroll">
<thead style="background-color: #99E1D9; color: #705D56;">
<tr>
<th>ID</th>
<th>Name Client</th>
<th>Last Update</th>
<th style="padding-left: 30%;">Status</th>
</tr>
</thead>
<tbody id="hoverTable">
<?php
$connection = mysql_connect('localhost', 'root', '');
mysql_select_db('patientdb');
$query = "SELECT id, name, date FROM clients";
$result = mysql_query($query);
//status waarden uit
$status = "SELECT status FROM clients";
$status_ = mysql_query($status);
while($row = mysql_fetch_array($result)){ //Loop through results
echo "<tr>
<td>" . $row['id'] . "</td>
<td>" . $row['name'] . "</td>
<td>" . $row['date'] . "</td>
<td style='padding-left: 30%;'>";
if ($status_ > 60) {
echo "red";
} elseif ($status_ > 50) {
echo "yellow";
} else {
echo "green";
}
echo "</td>
</tr>";
}
mysql_close();
?>
</tbody>
</table>
You can't have an if statement (or any other statement, for that matter) in the middle of another statement like echo. If you want to concatenate different strings depending on a variable, you can use the conditional (AKA "ternary") operator.
echo "<tr>
<td>" . $row['id'] . "</td>
<td>" . $row['name'] . "</td>
<td>" . $row['date'] . "</td>
<td style='padding-left: 30%;'>" .
$status_ > 60 ? "red" : ($status_ > 50 ? "yellow" : "green" )
. "</td>
</tr>";
Try:
$status = "green";
if ($status > 50)
{
$status="yellow";
}
elseif($status>60)
{
$status="red";
}
echo "<tr>
<td>" . $row['id'] . "</td>
<td>" . $row['name'] . "</td>
<td>" . $row['date'] . "</td>
<td style='padding-left: 30%;'>" .$status. "</td>
</tr>";
You can't append to a string a conditional statement, assign to a variable first for example (like I posted)
This part isn't at the right place:
if ($status_ > 60){echo "red";
} elseif ($status_ > 50){echo "yellow";
} else{echo "green";}
should be:
echo "<tr>
<td>" . $row['id'] . "</td>
<td>" . $row['name'] . "</td>
<td>" . $row['date'] . "</td>
<td style='padding-left: 30%;'>";
if ($status_ > 60){
echo "red";
} elseif ($status_ > 50){
echo "yellow";
} else{
echo "green";
}
echo "</td></tr>";
Surely status_ would not come back with a number, but an array.
$status_ = mysql_query($status);
Without knowing what data is coming back, it is difficult to help.
mysql_query
I've been staring at this page for over an hour. My update function just doesnt not seem to update. When i tried it through sql it seems ok. I have a form at the bottom of this page which updates a field in a table. Can anyone spot the mistakes?
<?php
// First of all initialise the user and check for permissions
require_once "/var/www/users/user.php";
$user = new CHUser(2);
// Initialise the template
require_once "/var/www/template/template.php";
$template = new CHTemplate();
// And create a cid object
require_once "/var/www/Testing/DisplayWIPOnLocation.php";
$BundleProgress= new CHWIPProgress();
if(isset($_GET['Reference'])){
$todays_date = date("Y-m-d H:i:s");
$content .= " <h3> Details for Bundle : $reference </h3> ";
$bundle = $BundleProgress->GetBundle($_GET['Reference']);
$reference = $_GET['Reference'];
// Now show the details
foreach($bundle as $x){
$content .= "
<table>
<tr>
<th> Location </th>
<td>" . $x['Description'] . "</td>
</tr>
<tr>
<th> Works Order Number </th>
<td>" . $x['WorksOrder'] . "</td>
</tr>
<tr>
<th> Bundle Number </th>
<td>" . $x['Number'] . "</td>
</tr>
<tr>
<th>Qty Issued</th>
<td>" . $x['Qty'] . "</td>
</tr>
<tr>
<th>Bundle Reference </th>
<td>" . $x['Reference'] . "</td>
</tr>
<tr>
<th>Style description</th>
<td>" . $x['Stock'] . "</td>
</tr>
<tr>
<th>Due Date</th>
<td>" . $x['DueDate'] . "</td>
</tr>
<tr>
<th>Date In </th>
<td>" . $x['DateIN'] . "</td>
</tr>
<tr>
<th>Date Out</th>
<td>" . $x['DateOUT'] . "</td>
</tr>
<tr>
<th>Last Code</th>
<td>" . $x['Last'] . "</td>
</tr>
</table>
<br> ";
}
$content .= " </table>
<form action='viewBundle.php?step=2' method='post'>
<p>Reason: <input type='text' name='reason' /><br
/><p>
<p><input type='hidden' name='bundlereference'
id='Username' value='" . $x['Reference'] . "' />
<input type='submit' name ='add'/></form>
</table> ";
if($_GET['step'] == 2) {
$BundleProgress->UpdateReason($_POST['reason'],$_POST['bundlereference']);
$content .= " <a href='index.php?location=" .
$x['Description'] . "'> updated</a> ";
}
}
else {
$content .= "<h3>Something has gone wrong</h3>
<br>
<a href='index.php?location=" . $x['Description'] . "'> Return to Previous
Page </a>
";
}
$template->SetTag("content", $content);
echo $template->Display();
?>
Function
public function UpdateReason($reason, $bundlereference) {
$sql = "UPDATE `ArchiveBundle`
SET `Issue` = " . $reason . "
WHERE `BundleReference` = " . $bundlereference .
";";
mysql_select_db(DB_DATABASE_NAME, $this->conn);
return mysql_query($sql, $this->conn);
}
change:
if($_GET['step'] == 2)
to:
if((int)$_GET['step'] === 2)
and:
public function UpdateReason($reason, $bundlereference) {
$sql = "UPDATE `ArchiveBundle`
SET `Issue` = " . $reason . "
WHERE `BundleReference` = " . $bundlereference .
";";
mysql_select_db(DB_DATABASE_NAME, $this->conn);
return mysql_query($sql, $this->conn);
}
to:
public function UpdateReason($reason, $bundlereference) {
mysql_select_db(DB_DATABASE_NAME, $this->conn);
$_reason = mysql_real_escape_string($reason,$this->conn);
$_bundlereference = mysql_real_escape_string($bundlereference,$this->conn);
$sql = "UPDATE `ArchiveBundle`
SET `Issue` = '" . $_reason . "'
WHERE `BundleReference` = '" . $_bundlereference . "'";
return mysql_query($sql, $this->conn);
}
Try that. Code hasn't been tested but it's a good place to start.
To try and debug what's going on here do the following:
public function UpdateReason($reason, $bundlereference) {
error_reporting(E_ALL ^ E_NOTICE);
$db_selected = mysql_select_db(DB_DATABASE_NAME, $this->conn);
if (!$db_selected) {
die("Can't use db : " . mysql_error());
}
$_reason = mysql_real_escape_string($reason,$this->conn);
$_bundlereference = mysql_real_escape_string($bundlereference,$this->conn);
$sql = "UPDATE `ArchiveBundle`
SET `Issue` = '" . $_reason . "'
WHERE `BundleReference` = '" . $_bundlereference . "'";
mysql_query($sql, $this->conn);
die(mysql_error());
}
Also, it looks like on your form submission you're not passing in the Reference parameter so the if(isset($_GET['Reference'])) will fail when you post the form. I've change the table and form code below to make it more readable, pass in the Reference param on form submission, and also to update the db record BEFORE fetching the dataset so you'll see the updated records in the table returned.
// First of all initialise the user and check for permissions
require_once "/var/www/users/user.php";
$user = new CHUser(2);
// Initialise the template
require_once "/var/www/template/template.php";
$template = new CHTemplate();
// And create a cid object
require_once "/var/www/Testing/DisplayWIPOnLocation.php";
$BundleProgress= new CHWIPProgress();
if(isset($_GET['Reference'])){
if($_GET['step'] == 2) {
$BundleProgress->UpdateReason($_POST['reason'],$_POST['bundlereference']);
}
$todays_date = date("Y-m-d H:i:s");
$content .= " <h3> Details for Bundle : $reference </h3> ";
$bundle = $BundleProgress->GetBundle($_GET['Reference']);
$reference = $_GET['Reference'];
// Now show the details
foreach($bundle as $x){
$content .= "
<table>
<tr><th> Location </th><td>" . $x['Description'] . "</td></tr>
<tr><th> Works Order Number </th><td>" . $x['WorksOrder'] . "</td></tr>
<tr><th> Bundle Number </th><td>" . $x['Number'] . "</td></tr>
<tr><th>Qty Issued</th><td>" . $x['Qty'] . "</td></tr>
<tr><th>Bundle Reference </th><td>" . $x['Reference'] . "</td></tr>
<tr><th>Style description</th><td>" . $x['Stock'] . "</td></tr>
<tr><th>Due Date</th><td>" . $x['DueDate'] . "</td></tr>
<tr><th>Date In </th><td>" . $x['DateIN'] . "</td></tr>
<tr><th>Date Out</th><td>" . $x['DateOUT'] . "</td></tr>
<tr><th>Last Code</th><td>" . $x['Last'] . "</td></tr>
</table>
<br>";
}
$content .= "<table>
<form action='viewBundle.php?Reference=" . $_GET['Reference'] . "&step=2' method='post'>
<p>Reason: <input type='text' name='reason' /></p><br/>
<p><input type='hidden' name='bundlereference' id='Username' value='" . $x['Reference'] . "' /></p>
<input type='submit' name ='add'/>
</form>
</table>";
} else {
$content .= "<h3>Something has gone wrong</h3>
<br>
<a href='index.php?location=" . $x['Description'] . "'> Return to Previous Page </a>
";
}
$template->SetTag("content", $content);
echo $template->Display();
Can I advise you break this down by first checking what mysql_query returns. It maybe that this particular variable is defined incorrectly. Also remember add quotes to the values in your query.