嗨,有人可以在这里指出我的错误。我有两个PHP文件。第一个view.php如下;第二个是processor.php 我看到if(常量('SELECTitem')== $ i)行没有捕获要与$ i进行比较的所需输入,因此直接进入'else'验证。请指正。感谢。
<?php
$con=mysql_connect('localhost','root') or die ("Server connection failure!");
$db=mysql_select_db('regional_data',$con) or die ("Couldn't connect the database");
$SQL="SELECT sbstart, sbend FROM newchk";
$run=mysql_query($SQL,$con) or die ("SQL Error");
$nor=mysql_num_rows($run);
define("SELECTitem", form.options.value);
?>
<html>
<head><title></title>
<script type="text/javascript">
function ValidateData(form)
{
var TextIn = document.getElementById('txtN');
if(form.txtN.value == "")
{
alert("Text field is empty");
return false;
}else{
alert ((form.options[form.options.selectedIndex].value) + (form.txtN.value));
}
}
</script>
</head>
<body>
<form onsubmit="return ValidateData(this)" method="POST" action="processor.php">
<select STYLE='width:90px' name="options"><?php
while ($rec = mysql_fetch_array($run))
{
for($i=$rec['sbstart']; $i<=$rec['sbend']; $i++)
{
echo "<option id='options' value='$i'>$i<br></option>";
}
}
?>
</select>
<input type="text" id="txtN">
<input type="submit" name="subN" value="Save">
</form>
</body>
</html>
<?php
$con=mysql_connect('localhost','root') or die ("Server connection failure!");
$db=mysql_select_db('regional_data',$con) or die ("Couldn't connect the database");
$SQL="SELECT * FROM newchk";
$run=mysql_query($SQL,$con) or die ("SQL Error");
$nor=mysql_num_rows($run);
while ($rec = mysql_fetch_array($run))
{
for($i=$rec['sbstart']; $i<=$rec['sbend']; $i++)
{
if(constant('SELECTitem') == $i)
{
if($rec['totsb'] <= "0")
{
echo "You have already entred this cheque number.";
return false;
} else {
echo "You can proceed withi this entry";
return false;
}
}
else
{ echo "Error: Cant find choosen in the databse";
return false;
}
}
}
?>
答案 0 :(得分:2)
当您提交到processor.php时,您在上一页中创建的常量将不会被转移。此外,在定义常量时,无法在PHP中访问JavaScript。所以你创造的常数......
define("SELECTitem", form.options.value);
echo SELECTitem; // returns "formoptionsvalue" (form concatenated with options and value)
您应该做的是提交form.options.value并通过$ _POST访问它。
答案 1 :(得分:0)
define("SELECTitem", form.options.value);
“form.options.value”是什么意思? 如果我理解正确,那就是你的JS代码。 但它并不像那样。
此外,您无法从其他进程访问常量。
您需要先阅读一些PHP书籍。