我有一个 ecrtst.php,它有 3 个输入字段,在提交时 - submit-ecr.php。我需要将数据写入 mysql 表,验证是否没有空白字段。当我提交所有值时它工作正常,成功提交后它会返回到 ecrtst.php,但是当我留下空白字段时,它无法显示错误。
让我知道我们是否可以在 javascript 或 php 中显示错误,然后返回上一页。
ecrtst.php 文件:
<?php
$dbservertype='mysql';
$servername='localhost';
$dbusername='hitec';
$dbpassword='!@#';
$dbname='hitec';
connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}
//////// End of connecting to database ////////
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head id="Head1" runat="server">
<title>ECR</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("form:not(.filter) :input:visible:enabled:first").focus();
});
</script>
</head>
<body document.f1.ecrno.focus();">
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#026465">
<tr>
<td><div align="center"><center class="style6">ECR</center>
<center>
<?php
$rowec=mysql_query("SELECT Ecrno FROM ECRHDR_draft WHERE usr='$user'");
$rowec2=mysql_fetch_assoc($rowec);
$rowec3=$rowec2['Ecrno'];
?>
<form name='f1' id='f1'>
<table width="600" border="0" cellspacing="1" cellpadding="0">
<tr>
<td width="60"><span class='style5'>ECR No.</span></td>
<td width="99"><input name="ecrno" type="text" size="10" maxlength="10" value="<?=$rowec3;?>" onchange="showecr(this.value);"></td>
<?php
$rowarea=mysql_query("SELECT Area FROM ACMAST");
$rowarea2=mysql_fetch_assoc($rowarea);
$rowarea3=$rowarea2['Area'];
?>
<td width="180"><select name='area' onchange="showarea(this.value);">
<option value='<?=$rowarea3;?>'> <?=$rowarea3;?> <option>
<option value='Rajajinagar'>Rajajinagar</option>
<option value='Jayanagar'>Jayanagar</option>
<option value='Chennai'>Chennai</option>
</select></td>
<?php $script_dt = date('d/m/Y'); ?>
<td width="72"><span class='style5'>ECR Date:</span></td>
<td width="189"><input name="ecrdate" type="text" size="10" maxlength="10" value="<?=$script_dt;?>" onchange="showecrdate(this.value);"> <span class='style5'>(d/m/yyyy)</span> </td>
</tr>
</table>
<a href="submit-ecr.php" target="_parent" accesskey="s" ><input name="SAVE" type="button" value="SAVE ECR !">
</form>
</center>
</body>
</html>
提交-ecr.php 文件:
<?php
ob_start();
$con = mysql_connect("localhost","hitec","@#");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("hitec", $con);
//-----Checking for blank fields in ECRHDR-draft file. ------------------------//
$rowexist=mysql_query("select Ecrno from ECRHDR_draft WHERE usr='$user'");
$data=mysql_fetch_array($rowexist);
if ($data[Ecrno] <= 0 || $data[Ecrno]='')
{
echo "<span class='sty1'><center>DONOT LEAVE EMPTY FIELDS for ECR No.</CENTER><br> <br></span>";
echo " <span class='sty1'><center><a href=\"javascript:PreviousPage();\">CLICK HERE TO GO BACK !!!!</a></CENTER></span>";
}
$URL="http://www.samplesite.info/svga//ecrtst.php";
header('WWW-Authenticate: Negotiate');
header('WWW-Authenticate: NTLM', false);
header ('Location:'.$URL);
mysql_close($con);
ob_flush();?>