<?php
session_start();
?>
<html>
<head>
<link rel="stylesheet" href="css/bootstrap.css">
<script>
function submit() {
document.getElementById("myform").submit();
}
window.onload = function() {
document.getElementById("textbox").focus();
};
</script>
</head>
<body>
<form id="myform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<h1> AWB_NO</h1>
<input type=text id="textbox" name="excel" onchange="submit()">
</br>
</form>
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
$vars = $_COOKIE['var1'];
if(!isset($_SESSION['items'])) {
$_SESSION['items'] = array();
}
if(!isset($_SESSION['arr2'])) {
$_SESSION['arr2'] = array();
}
$var='';
if(isset($_POST['excel']))
{
$host="localhost";
$user="root";
$password="";
$db="greenmobiles";
$table="manifest";
$var=$_POST['excel'];
$con=mysqli_connect("$host","$user","$password") or die("Cannot Connect");
mysqli_select_db($con,"$db") or die("Cannot select DB!");
if (in_array($var,$_SESSION['items']))
{
echo"The new value has been scanned!</br>";
echo "<hr>";
echo "The tracking id's of the currently scanned items are given below<br><hr>";
foreach ($_SESSION['items'] as $x => $value)
{
echo "$value";
echo "<br>";
}
echo "<script>alert('oops! This item has already been scanned!')</script>";
}
else
{
$sql = "SELECT * FROM manifest WHERE awb_no = '$var'";
$result = mysqli_query($con,$sql);
if(mysqli_num_rows($result) > 0)
{
echo "tracking id present in the manifest</br>";
}
else
{
echo "<script>alert('Tracking id is not present in the manifest!')</script>";
}
$sqli = "SELECT * FROM manifest WHERE (awb_no = '$var') AND (document_no='$vars')";
$result1 = mysqli_query($con,$sqli);
if (mysqli_num_rows($result1))
{
echo "The tracking id matches with the document no.";
}
else
{
echo "<script>alert('Tracking id does not belong to the document number entered.')</script>";
exit(0);
}
while ($row = mysqli_fetch_assoc($result))
{
$_SESSION['data'][] = $row['awb_no'];
$_SESSION['items'] = $_SESSION['data'];
}
mysqli_free_result($result);
echo"The new value has been scanned!</br>";
echo "<hr>";
echo "The tracking id's of the currently scanned items are given below<br><hr>";
echo '<div class="col-lg-10 col-lg-offset-1 panel">'."<table class='table'>
<tr>
<th>Document No</th>
<th>AWB NO</th>
<th>Order Id</th>
<th>Forms</th>
<th>Extras</th>
</tr>";
echo "<tr>";
$sqlq= "SELECT * FROM manifest WHERE awb_no = '$var'";
$result2 = mysqli_query($con,$sqlq);
if ($result2)
{
while ($row=mysqli_fetch_row($result2))
{
echo "<tr>";
echo "<td>" . $row[0] . "</td>";
echo "<td>" . $row[1] . "</td>";
echo "<td>" . $row[2] . "</td>";
echo "<td>" . $row[3] . "</td>";
echo "<td>" . $row[4] . "</td>";
echo "</tr>";
}
echo "</table></div>";
}
}
}
else
{
session_destroy();
}
?>
</body>
</html>
Hello, i am new to php and html. I am giving an input to a text box whose value is '$var' and retrieving data one row at a time and trying to print it in a html table via php. But each time i enter a value the previous row gets overwritten by the new row and i am not able to keep the previous rows and append the new ones to my table. Can someone please tell me where i am going wrong.