0

嗨,有人可以在这里指出我的错误。我有两个 PHP 文件。第一个view.php如下;第二个作为 processor.php 我看到 if(constant('SELECTitem') == $i) 行没有捕获要与 $i 进行比较的所需输入,因此直接进入“else”验证。请纠正我。谢谢。

视图.php

<?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

<?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;
     }
    }
}
?>
4

3 回答 3

2

When you submit to processor.php, the constant you created in the previous page will not be carried over. Also, when you are defining the constant, you cannot access JavaScript in PHP. So the constant you created...

define("SELECTitem", form.options.value);
echo SELECTitem; // returns "formoptionsvalue" (form concatenated with options and value)

What you should do is submit form.options.value and access it via $_POST.

于 2012-09-09T17:49:58.233 回答
0
 define("SELECTitem", form.options.value);

What does "form.options.value" mean? If i understand it right, it's your JS code. But it doesn't work like that.

Also u can not access constant from other process.

You need to read some PHP books first.

于 2012-09-09T17:50:45.040 回答
0

问题的标题很好而且很笼统:找不到常量错误 - PHP但它的主体非常特别

对于所有来这里寻求一般答案的人,请注意,当您来到这里是为了获得一个非工作类常量时,请检查您是否使用了该类的完全限定名称,否则它将不起作用。

挪威克朗:constant('MyClass::MY_CONST');

好的:constant(MyClass::class . '::MY_CONST');

于 2021-10-20T09:11:32.313 回答