Question
<?php IF () { } ?>
I am having a problem with my code and I seem not to be
getting the result I want. I tried different tests to see if it is
my code or my database. I am trying to make a if statement where if
administration creates a student that if someone else has the same
student number it will give the administrator an error.
I have made a recordset called "studentNo" which contains a student name, address and their student number which is a "int" of 9 characters. I am using mySQL.
As an example of what the database looks like as such
Student No. User
1 200777895 Darryl
2 333333333 Michael
3 987654321 Fred
4 123456789 Carolina
Now this is my code of an if statement.
if ($_POST['stNum'] == $row_studentNo['stNum']){
$error['studentNumber'] = 'This student number has already been assigned, please enter a new student number';
}
When my if code looks on the recordset called "studentNo" it finds no matching student numbers so it thinks there are no duplicates when I've entered a series of 9 numbers in a form field. If I type 200777895 student number the error message comes up and tells me that someone has that student number. If I type in the form field a different number 333333333 it shows there is no error and that student number is available. I noticed that the 200777895 student number is my first user on my list in the database and somehow the code does not search the whole database for other student numbers.
I have tested to see if it is my code and when I change the code to search the actual student number instead of the recordset studentNo, I get my error message saying that student number has been taken.
Here is the test if code I used.
if ($_POST['stNum'] == 123456789){
$error['studentNumber'] = 'This student number has already been assigned, please enter a new student number';
}
I do not know what I am doing wrong in this code below where it is not searching my whole recordset of studentNo.
if ($_POST['stNum'] == $row_studentNo['stNum']){
$error['studentNumber'] = 'This student number has already been assigned, please enter a new student number';
}
I can't figure out what am I doing wrong, anyone have any ideas?
I have made a recordset called "studentNo" which contains a student name, address and their student number which is a "int" of 9 characters. I am using mySQL.
As an example of what the database looks like as such
Student No. User
1 200777895 Darryl
2 333333333 Michael
3 987654321 Fred
4 123456789 Carolina
Now this is my code of an if statement.
if ($_POST['stNum'] == $row_studentNo['stNum']){
$error['studentNumber'] = 'This student number has already been assigned, please enter a new student number';
}
When my if code looks on the recordset called "studentNo" it finds no matching student numbers so it thinks there are no duplicates when I've entered a series of 9 numbers in a form field. If I type 200777895 student number the error message comes up and tells me that someone has that student number. If I type in the form field a different number 333333333 it shows there is no error and that student number is available. I noticed that the 200777895 student number is my first user on my list in the database and somehow the code does not search the whole database for other student numbers.
I have tested to see if it is my code and when I change the code to search the actual student number instead of the recordset studentNo, I get my error message saying that student number has been taken.
Here is the test if code I used.
if ($_POST['stNum'] == 123456789){
$error['studentNumber'] = 'This student number has already been assigned, please enter a new student number';
}
I do not know what I am doing wrong in this code below where it is not searching my whole recordset of studentNo.
if ($_POST['stNum'] == $row_studentNo['stNum']){
$error['studentNumber'] = 'This student number has already been assigned, please enter a new student number';
}
I can't figure out what am I doing wrong, anyone have any ideas?
