<html>
<body>
<form method="post" action="#">
<h1> AB_NO</h1>
<input type=text name="excel"> //input values that need to be checked for presence in database.
<input type=submit name="submit">
</form>
<?php
session_start();
if(isset($_POST['submit']))
{
$host="localhost";
$user="root";
$password="";
$db="green";
$table="manitable";
mysql_connect("$host","$user","$password") or die("Cannot Connect");
mysql_select_db("$db") or die("Cannot select DB!");
$var=$_POST['excel'];
$sql="SELECT * FROM manitable WHERE (ab_no = '$var')";
$result=mysql_query($sql);
$data_item=array();
$items=array();
if (mysql_num_rows($result) == 1) {
print 'Product Exists' ;
while ($row = mysql_fetch_array($result)) {
$data_item['doc_no'] = $row['doc_no'];
$data_item['ab_no'] = $row['ab_no'];
$data_item['od_id'] = $row['od_id'];
$items[] = $data_item;
}
print_r($items);
}
else {
print 'Sorry, this Product is not present' ;
}
}
?>
</body>
</html>
The above code is the code I am using.
The form field with name=excel
takes in different strings at a time. On each value entered I want it to be stored in the $items
array. The value entered in form field is checked if it is present in database. If present it must be stored in the $items
array along with the other column values. Initially a value is entered in the field and the value along with the corresponding column entries are stored in the items array.
The items array at an index value of 0 will hold the corresponding values from the form value that is sent. Now when a second value is again passed through the form I want it to be stored in the array as a second entry in the items array.
My manitable
table in database has the following columns:
doc_no
-
ab_no
od_id
The output is:
Product ExistsArray ( [0] => Array ( [doc_no] => 202344223341312 [ab_no] => SMLP3105153342 [od_id] => ODRD3028479929633865301 ) )
I want the new ab_no
entries which are matched on comparison with db values to be added to the [1], [2] and so on indices of the items array.
Thanks in advance.