<html><head>
<script>
function submit() {
document.getElementById("myform").submit();
}
</script>
</head>
<body>
<form id="myform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<h1> AWB_NO</h1>
<input type=text name="excel" onchange="submit()" >
</br>
</form>
<?php
session_start();
$vars = $_COOKIE['var1'];
//$vars=$_GET['doc'];
if(!isset($_SESSION['items'])) {
$_SESSION['items'] = array();
}
$var='';
if(isset($_POST['submit']))
{
$host="localhost";
$user="root";
$password="";
$db="greenmobiles";
$table="manifest";
$var=$_POST['excel'];
//$vars=$_POST['doc'];
mysql_connect("$host","$user","$password") or die("Cannot Connect");
mysql_select_db("$db") or die("Cannot select DB!");
/*$sqlcommand="SELECT document_no FROM manifest WHERE (document_no = '$vars')";
$doc_res = mysql_query($sqlcommand);
while($col = mysql_fetch_array($doc_res)){
if($col['document_no']==$vars)
{
echo "Document number is correct</br>";
break;
}}
if($col['document_no']!==$vars)
{
echo "Please check the document no entered";
exit(0);
}*/
if (in_array($var,$_SESSION['items']))
{
echo "<script>alert('oops! This item has already been scanned!')</script>";
}
else
{
$sql = "SELECT * FROM manifest WHERE (awb_no = '$var')";
$result = mysql_query($sql);
if(mysql_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 = mysql_query($sqli);
if (mysql_num_rows($result1))
{
echo "The tracking id matches with the document no.";
# code...
}
else
{
echo "<script>alert('Tracking id does not belong to the document number entered.')</script>";
exit(0);
}
while ($row = mysql_fetch_array($result)) {
$_SESSION['data'][] = $row['awb_no'];
$_SESSION['items'] = $_SESSION['data'];
}
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>";
# code...
}
}
}
else
{
session_destroy();
}
?>
</body>
</html>
喂!我是javascript,php和html的新手。在这里,当我尝试使用javascript提交而不是提交按钮时,我的php脚本似乎没有执行。如何解决这个问题?请帮忙! P.S我不想使用提交按钮。
答案 0 :(得分:1)
您的脚本有很多错误。 激活你的php错误显示:
ini_set('error_reporting', E_ALL);
ini_set('display_errors', true);
首先,必须先启动会话才能发送标头。 所以用以下文件开始文件:
<?php
session_start();
?>
<html>
...
其次,全局$ _POST包含一个带有&#39; name&#39;的数组。属性
<input type=text name="excel" onchange="submit()" >
<?php
if(isset($_POST['excel'])) { ... }
答案 1 :(得分:0)
if(isset($_POST['submit'])) is wrong type `if(isset($_POST['name']))`