Couldn't find constant error - PHP

Hi can some one please point out my mistake here. I've got two PHP files. First view.php goes as follows; and the second as processor.php I see the if(constant('SELECTitem') == $i) line doesnt capture the desired input to be compared with $i hence straight goes to 'else' validation. Please correct me. Thanks.

view.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> 
processor.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;
     }
    }
}
?>

Answers


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.


Need Your Help

php multidimensional array flatten only for numeric keys

php multidimensional-array

I've been struggling around with a problem which I can't get resolved for hours. I want to have a special designed multidimensional array.

How to refactor in a branch without losing my mind?

refactoring branch

I refactor my and other people's code all the time.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.