【发布时间】:2015-10-20 04:02:33
【问题描述】:
<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>
上面的代码是我正在使用的代码。
name=excel 的表单域一次接受不同的字符串。在输入的每个值上,我希望它存储在 $items 数组中。检查表单字段中输入的值是否存在于数据库中。如果存在,它必须与其他列值一起存储在 $items 数组中。最初在字段中输入一个值,该值与相应的列条目一起存储在 items 数组中。
索引值为 0 的 items 数组将保存来自发送的表单值的相应值。现在,当第二个值再次通过表单传递时,我希望它作为 items 数组中的第二个条目存储在数组中。
我在数据库中的manitable 表有以下列:
doc_no-
ab_no od_id
输出是:
Product ExistsArray ( [0] => Array ( [doc_no] => 202344223341312 [ab_no] => SMLP3105153342 [od_id] => ODRD3028479929633865301 ) )
我希望将在与 db 值比较时匹配的新 ab_no 条目添加到 items 数组的 [1]、[2] 等索引中。
提前致谢。
【问题讨论】: