wiltang2004
Programmer
- Jan 26, 2025
- 1
I need help as I ran SQL query below
<html>
<head>
</head>
<body>
List of Unapproved requests<br><br>
Please only approve 1 request at any one time
<form action="customerinfotest2.php" method="post" style="margin:0px">
<?php
$currentdate=date("YmdHi");
$servername =
$database =
$username =
$password =
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
mysql_select_db("alanbus", $conn);
$sql = "SELECT * FROM blg WHERE status='not approve'";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($result)) {
$res_id = stripslashes($row['res_id']);
$status = stripslashes($row['status']);
$order_no = stripslashes($row['order_no']);
$res_orgname = stripslashes($row['res_orgname']);
$res_name = stripslashes($row['res_name']);
$res_email = stripslashes($row['res_email']);
$res_tel = stripslashes($row['res_tel']);
$res_date = stripslashes($row['res_date']);
$department = stripslashes($row['department']);
$res_fromlocation = stripslashes($row['res_fromlocation']);
$postal1 = stripslashes($row['postal1']);
$res_tolocation = stripslashes($row['res_tolocation']);
$postal2 = stripslashes($row['postal2']);
$time_start = stripslashes($row['time_start']);
$time_end = stripslashes($row['time_end']);
$numberpax = stripslashes($row['numberpax']);
$bustype1 = stripslashes($row['bustype1']);
$seaternumber1 = stripslashes($row['seaternumber1']);
$bustype2 = stripslashes($row['bustype2']);
$seaternumber2 = stripslashes($row['seaternumber2']);
$numberbus = stripslashes($row['numberbus']);
$way = stripslashes($row['way']);
$ishpickup = stripslashes($row['ishpickup']);
$remarks = stripslashes($row['remarks']);
//and any other variables you need for the email...
echo <<<STR
<table border=1px;border-collapse=collapse>
<tr>
<th>approval</th>
<th>Order no</th>
<th>Org name</th>
<th>name</th>
<th>email</th>
<th>tel</th>
<th>date</th>
<th>department</th>
<th>From location</th>
<th>Postal1</th>
<th>To location</th>
<th>Postal2</th>
<th>Time start</th>
<th>Time end</th>
<th>No pax</th>
<th>bustype1</th>
<th>seaternumber1</th>
<th>bustype2</th>
<th>seaternumber2</th>
<th>number of bus</th>
<th>way</th>
<th>ISH pickup</th>
<th>remarks</th>
</tr>
<tr>
<td>
<input type="checkbox" name="ReportData[$i]" value="$i">
</td><td>
<input type="text" name="order_no[$i]" value="{$row['order_no']}" />
</td><td>
<input type="text" name="res_orgname[$i]" value="{$row['res_orgname']}" />
</td><td>
<input type="text" name="res_name[$i]" value="{$row['res_name']}" />
</td><td>
<input type="text" name="res_email[$i]" value="{$row['res_email']}" />
</td><td>
<input type="text" name="res_tel[$i]" value="{$row['order_tel']}" />
</td><td>
<input type="text" name="res_date[$i]" value="{$row['res_date']}" />
</td><td>
<input type="text" name="department[$i]" value="{$row['department']}" />
</td><td>
<input type="text" name="res_fromlocation[$i]" value="{$row['res_fromlocation']}" />
</td><td>
<input type="text" name="postal1[$i]" value="{$row['postal1']}" />
</td><td>
<input type="text" name="res_tolocation[$i]" value="{$row['res_tolocation']}" />
</td><td>
<input type="text" name="postal2[$i]" value="{$row['postal2']}" />
</td><td>
<input type="text" name="time_start[$i]" value="{$row['time_start']}" />
</td><td>
<input type="text" name="time_end[$i]" value="{$row['time_end']}" />
</td><td>
<input type="text" name="numberpax[$i]" value="{$row['numberpax']}" />
</td><td>
<input type="text" name="bustype1[$i]" value="{$row['bustype1']}" />
</td><td>
<input type="text" name="seaternumber1[$i]" value="{$row['seaternumber1']}" />
</td><td>
<input type="text" name="bustype2[$i]" value="{$row['bustype2']}" />
</td><td>
<input type="text" name="seaternumber2[$i]" value="{$row['seaternumber2']}" />
</td><td>
<input type="text" name="numberbus[$i]" value="{$row['numberbus']}" />
</td><td>
<input type="text" name="way[$i]" value="{$row['way']}" />
</td><td>
<input type="text" name="ishpickup[$i]" value="{$row['ishpickup']}" />
</td><td>
<input type="text" name="remarks[$i]" value="{$row['remarks']}" />
</td></tr>
</table>
STR;
}
mysql_close($conn)
?>
<br><br> <input name="submit1" type="submit" value="approve" />
</form>
</body></html>
And tried to get the clicked row data to be sent out in email and update in sql as below
<html>
<head>
</head>
<body>
<?php
{
foreach ($_POST['ReportData'] as $cbox=>$cboxvalue):
echo "order_no = {$_POST['order_no'][$cbox]}; <br/> res_orgname = {$_POST['res_orgname'][$cbox]};<br/>;
res_name = {$_POST['res_name'][$cbox]}; <br/> res_email = {$_POST['res_email'][$cbox]};<br/>;
res_tel = {$_POST['res_tel'][$cbox]}; <br/> res_date = {$_POST['res_date'][$cbox]};<br/>;
department = {$_POST['department'][$cbox]}; <br/> res_fromlocation = {$_POST['res_fromlocation'][$cbox]};<br/>;
postal1 = {$_POST['postal1'][$cbox]}; <br/> res_tolocation = {$_POST['res_tolocation'][$cbox]};<br/>;
postal2 = {$_POST['postal2'][$cbox]}; <br/> time_start = {$_POST['time_start'][$cbox]};<br/>;
tme_end = {$_POST['time_end'][$cbox]}; <br/> numberpax = {$_POST['numberpax'][$cbox]};<br/>;
bustype1 = {$_POST['bustype1'][$cbox]}; <br/> seaternumber1 = {$_POST['seaternumber1'][$cbox]};<br/>;
bustype2 = {$_POST['bustype2'][$cbox]}; <br/> seaternumber2 = {$_POST['seaternumber2'][$cbox]};<br/>;
numberbus = {$_POST['numberbus'][$cbox]}; <br/> way = {$_POST['way'][$cbox]};<br/>;
ishpickup = {$_POST['ishpickup'][$cbox]}; <br/> remarks = {$_POST['remarks'][$cbox]};<br/>";
endforeach;
}
{
$order_no =$_POST['order_no'][$cbox];
$res_orgname =$_POST['res_orgname'][$cbox];
$res_name =$_POST['res_name'][$cbox];
$res_email =$_POST['res_email'][$cbox];
$res_tel =$_POST['res_tel'][$cbox];
$res_date =$_POST['res_date'][$cbox];
$department =$_POST['department'][$cbox];
$res_fromlocation =$_POST['res_fromlocation'][$cbox];
$postal1 =$_POST['postal1'][$cbox];
$res_tolocation =$_POST['res_tolocation'][$cbox];
$postal2 =$_POST['postal2'][$cbox];
$time_start =$_POST['time_start'][$cbox];
$time_end =$_POST['time_end'][$cbox];
$numberpax =$_POST['numberpax'][$cbox];
$bustype1 =$_POST['bustype1'][$cbox];
$seaternumber1 =$_POST['seaternumber1'][$cbox];
$bustype2 =$_POST['bustype2'][$cbox];
$seaternumber2 =$_POST['seaternumber2'][$cbox];
$numberbus =$_POST['numberbus'][$cbox];
$way =$_POST['way'][$cbox];
$ishpickup =$_POST['ishpickup'][$cbox];
$remarks =$_POST['remarks'][$cbox];
{
$to =
$subject = 'Booking form approved';
$message = 'The request below has been approved. Here are the details: '. "\n".
$message = 'Order No: '.$order_no. "\n".
$headers =
$headers .=
mail($to, $subject, $message, $headers);
$servername =
$username =
$password =
$db =
// Create connection
$conn = new mysqli($servername, $username, $password, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
mysql_select_db( , $conn);
$sql = "UPDATE blg SET status = 'approved', date_of_approval = $currentDateTime WHERE order_no = '$order_no'";
$result = mysqli_query($conn, $sql);
}
}
mysql_close($conn)
?>
</body></html>
But it always detect the 1st row data even though I checked the check box on the other rows and did not check the 1st row, see if can help?
And cant seem to get the update to work? Should update only those rows checked
<html>
<head>
</head>
<body>
List of Unapproved requests<br><br>
Please only approve 1 request at any one time
<form action="customerinfotest2.php" method="post" style="margin:0px">
<?php
$currentdate=date("YmdHi");
$servername =
$database =
$username =
$password =
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
mysql_select_db("alanbus", $conn);
$sql = "SELECT * FROM blg WHERE status='not approve'";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($result)) {
$res_id = stripslashes($row['res_id']);
$status = stripslashes($row['status']);
$order_no = stripslashes($row['order_no']);
$res_orgname = stripslashes($row['res_orgname']);
$res_name = stripslashes($row['res_name']);
$res_email = stripslashes($row['res_email']);
$res_tel = stripslashes($row['res_tel']);
$res_date = stripslashes($row['res_date']);
$department = stripslashes($row['department']);
$res_fromlocation = stripslashes($row['res_fromlocation']);
$postal1 = stripslashes($row['postal1']);
$res_tolocation = stripslashes($row['res_tolocation']);
$postal2 = stripslashes($row['postal2']);
$time_start = stripslashes($row['time_start']);
$time_end = stripslashes($row['time_end']);
$numberpax = stripslashes($row['numberpax']);
$bustype1 = stripslashes($row['bustype1']);
$seaternumber1 = stripslashes($row['seaternumber1']);
$bustype2 = stripslashes($row['bustype2']);
$seaternumber2 = stripslashes($row['seaternumber2']);
$numberbus = stripslashes($row['numberbus']);
$way = stripslashes($row['way']);
$ishpickup = stripslashes($row['ishpickup']);
$remarks = stripslashes($row['remarks']);
//and any other variables you need for the email...
echo <<<STR
<table border=1px;border-collapse=collapse>
<tr>
<th>approval</th>
<th>Order no</th>
<th>Org name</th>
<th>name</th>
<th>email</th>
<th>tel</th>
<th>date</th>
<th>department</th>
<th>From location</th>
<th>Postal1</th>
<th>To location</th>
<th>Postal2</th>
<th>Time start</th>
<th>Time end</th>
<th>No pax</th>
<th>bustype1</th>
<th>seaternumber1</th>
<th>bustype2</th>
<th>seaternumber2</th>
<th>number of bus</th>
<th>way</th>
<th>ISH pickup</th>
<th>remarks</th>
</tr>
<tr>
<td>
<input type="checkbox" name="ReportData[$i]" value="$i">
</td><td>
<input type="text" name="order_no[$i]" value="{$row['order_no']}" />
</td><td>
<input type="text" name="res_orgname[$i]" value="{$row['res_orgname']}" />
</td><td>
<input type="text" name="res_name[$i]" value="{$row['res_name']}" />
</td><td>
<input type="text" name="res_email[$i]" value="{$row['res_email']}" />
</td><td>
<input type="text" name="res_tel[$i]" value="{$row['order_tel']}" />
</td><td>
<input type="text" name="res_date[$i]" value="{$row['res_date']}" />
</td><td>
<input type="text" name="department[$i]" value="{$row['department']}" />
</td><td>
<input type="text" name="res_fromlocation[$i]" value="{$row['res_fromlocation']}" />
</td><td>
<input type="text" name="postal1[$i]" value="{$row['postal1']}" />
</td><td>
<input type="text" name="res_tolocation[$i]" value="{$row['res_tolocation']}" />
</td><td>
<input type="text" name="postal2[$i]" value="{$row['postal2']}" />
</td><td>
<input type="text" name="time_start[$i]" value="{$row['time_start']}" />
</td><td>
<input type="text" name="time_end[$i]" value="{$row['time_end']}" />
</td><td>
<input type="text" name="numberpax[$i]" value="{$row['numberpax']}" />
</td><td>
<input type="text" name="bustype1[$i]" value="{$row['bustype1']}" />
</td><td>
<input type="text" name="seaternumber1[$i]" value="{$row['seaternumber1']}" />
</td><td>
<input type="text" name="bustype2[$i]" value="{$row['bustype2']}" />
</td><td>
<input type="text" name="seaternumber2[$i]" value="{$row['seaternumber2']}" />
</td><td>
<input type="text" name="numberbus[$i]" value="{$row['numberbus']}" />
</td><td>
<input type="text" name="way[$i]" value="{$row['way']}" />
</td><td>
<input type="text" name="ishpickup[$i]" value="{$row['ishpickup']}" />
</td><td>
<input type="text" name="remarks[$i]" value="{$row['remarks']}" />
</td></tr>
</table>
STR;
}
mysql_close($conn)
?>
<br><br> <input name="submit1" type="submit" value="approve" />
</form>
</body></html>
And tried to get the clicked row data to be sent out in email and update in sql as below
<html>
<head>
</head>
<body>
<?php
{
foreach ($_POST['ReportData'] as $cbox=>$cboxvalue):
echo "order_no = {$_POST['order_no'][$cbox]}; <br/> res_orgname = {$_POST['res_orgname'][$cbox]};<br/>;
res_name = {$_POST['res_name'][$cbox]}; <br/> res_email = {$_POST['res_email'][$cbox]};<br/>;
res_tel = {$_POST['res_tel'][$cbox]}; <br/> res_date = {$_POST['res_date'][$cbox]};<br/>;
department = {$_POST['department'][$cbox]}; <br/> res_fromlocation = {$_POST['res_fromlocation'][$cbox]};<br/>;
postal1 = {$_POST['postal1'][$cbox]}; <br/> res_tolocation = {$_POST['res_tolocation'][$cbox]};<br/>;
postal2 = {$_POST['postal2'][$cbox]}; <br/> time_start = {$_POST['time_start'][$cbox]};<br/>;
tme_end = {$_POST['time_end'][$cbox]}; <br/> numberpax = {$_POST['numberpax'][$cbox]};<br/>;
bustype1 = {$_POST['bustype1'][$cbox]}; <br/> seaternumber1 = {$_POST['seaternumber1'][$cbox]};<br/>;
bustype2 = {$_POST['bustype2'][$cbox]}; <br/> seaternumber2 = {$_POST['seaternumber2'][$cbox]};<br/>;
numberbus = {$_POST['numberbus'][$cbox]}; <br/> way = {$_POST['way'][$cbox]};<br/>;
ishpickup = {$_POST['ishpickup'][$cbox]}; <br/> remarks = {$_POST['remarks'][$cbox]};<br/>";
endforeach;
}
{
$order_no =$_POST['order_no'][$cbox];
$res_orgname =$_POST['res_orgname'][$cbox];
$res_name =$_POST['res_name'][$cbox];
$res_email =$_POST['res_email'][$cbox];
$res_tel =$_POST['res_tel'][$cbox];
$res_date =$_POST['res_date'][$cbox];
$department =$_POST['department'][$cbox];
$res_fromlocation =$_POST['res_fromlocation'][$cbox];
$postal1 =$_POST['postal1'][$cbox];
$res_tolocation =$_POST['res_tolocation'][$cbox];
$postal2 =$_POST['postal2'][$cbox];
$time_start =$_POST['time_start'][$cbox];
$time_end =$_POST['time_end'][$cbox];
$numberpax =$_POST['numberpax'][$cbox];
$bustype1 =$_POST['bustype1'][$cbox];
$seaternumber1 =$_POST['seaternumber1'][$cbox];
$bustype2 =$_POST['bustype2'][$cbox];
$seaternumber2 =$_POST['seaternumber2'][$cbox];
$numberbus =$_POST['numberbus'][$cbox];
$way =$_POST['way'][$cbox];
$ishpickup =$_POST['ishpickup'][$cbox];
$remarks =$_POST['remarks'][$cbox];
{
$to =
$subject = 'Booking form approved';
$message = 'The request below has been approved. Here are the details: '. "\n".
$message = 'Order No: '.$order_no. "\n".
$headers =
$headers .=
mail($to, $subject, $message, $headers);
$servername =
$username =
$password =
$db =
// Create connection
$conn = new mysqli($servername, $username, $password, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
mysql_select_db( , $conn);
$sql = "UPDATE blg SET status = 'approved', date_of_approval = $currentDateTime WHERE order_no = '$order_no'";
$result = mysqli_query($conn, $sql);
}
}
mysql_close($conn)
?>
</body></html>
But it always detect the 1st row data even though I checked the check box on the other rows and did not check the 1st row, see if can help?
And cant seem to get the update to work? Should update only those rows checked