Php, Mysql Validation Malfunction And Search Doesn't Work?
Solution 1:
your variables like $fname $lname $gender $age $email $course
are put in if condition after if condition for isset($_POST['register'])
. Now even if your validation will work, data will still be entered in database. because you have put condition
if($fname&&$lname&&$gender&&$age&&$email&&$course)
Now control will enter that block when you have even a single value in all of those variable. What must be happening is, that you put wrong values, those are getting validated, message will be shown, but when first if block finishes, as $_POST variables still have SOME value, regardless of them being invalid, second if block will be entered and query will be fired.
What you can do is, where ever you are echoing error message, blank out that respective variable. something like this:
if (preg_match("/[a-zA-Z ]+$/", $_POST['fname'])) {
$fname = trim($_POST['fname']);
}
else
{
echo'<p>The First name is empty or has illegal characters! To edit please go the link Display Data Information</p>';
$fname = "";
}
Solution 2:
As for your first question, don't check for $var
, check for !empty($var)
.
Second question: I am not sure I understand what you are trying to do. But don't you mean $row
instead of $rows
when you are displaying something? Also, what if you have more than one search hit? What you want is:
while($row=mysql_fetch_assoc($result)){
echo$row['Firstname'], ' ', $row['LastName'];
}
instead of your if-else construction.
Post a Comment for "Php, Mysql Validation Malfunction And Search Doesn't Work?"