PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
hi im newbie in php i have my registration i check the script triple times but it always submit even there is no password input the validation was stop in email txtbox this is my code. sorry for my bad english
<?php
$LastName=$_POST['LastName'];
$FirstName=$_POST['FirstName'];
$MiddleName=$_POST['MiddleName'];
$eMail=$_POST['eMail'];
$PassWord1=$_POST['PassWord1'];
$PassWord2=$_POST['PassWord2'];
$Gender=$_POST['Gender'];
$Address=$_POST['Address'];
$BY=$_POST['BY'];
$BM=$_POST['BM'];
$BD=$_POST['BD'];
$CivilStatusID=$_POST['CivilStatusID'];
$ContactNo=$_POST['ContactNo'];
function check1($string) {
if (preg_match('/[^a-z-A-Z-]/', $string)) {
return false;
} else {
return true;
}
}
function check2($string) {
if(preg_match('/[^@.a-z-A-Z-0-9]/', $string)) {
return false;
} else {
return true;
}
}
function check3($string) {
if(preg_match('/[^0-9]/', $string)) {
return false;
} else {
return true;
}
}
if($LastName==""){
?><script>history.go(-1);alert('Last name is required.');</script><?php
echo $Age;
}
//check if is invalid string
if(ctype_digit($LastName)){
?><script>history.go(-1);alert('Number Are not Allowed in LastName');</script><?php
}
//check if is invalid string
if(!check1($LastName)){
?><script>history.go(-1);alert('Number with Alphabetic Are not allowed in LastName..!!');</script><?php
}
if($FirstName==""){
?><script>history.go(-1);alert('FirstName is required.');</script><?php
}
if(ctype_digit($FirstName)){
?><script>history.go(-1);alert('Number not allowed in FirstName.');</script><?php
}
if(!check1($FirstName)){
?><script>history.go(-1);alert('Number with Alphabetic are not Allowed in FirstName');</script><?php
}
if($MiddleName==""){
?><script>history.go(-1);alert('MiddleName is required.');</script><?php
}
if(ctype_digit($MiddleName)){
?><script>history.go(-1);alert('Number not allowed in MiddleName.');</script><?php
}
if(!check1($MiddleName)){
?><script>history.go(-1);alert('Number with Alphabetic are not Allowed in MiddleName')</script><?php
}
if($eMail==""){
?><script>history.go(-1);alert('Email is required');</script><?php
}
if(check2($eMail)){
?><script>history.go(-1);alert('Invalid Email Address');</script><?php
}
if(!check2($eMail)){
?><script>history.go(-1);alert('Invalid Email Address')</script><?php
}
if($PassWord1==""){
?><script>history.go(-1);alert('PassWord is required.');</script><?php
}
if(strlen($PassWord1) < 5){
?><script>history.go(-1);alert('Password Should be Greater Than five')</script><?php
}
if(!$PassWord1==$PassWord2){
?><script>history.go(-1);alert('Passwords not the same.');</script><?php
}
if($Address==""){
?><script>history.go(-1);alert('Address is required.');</script><?php
}
if($ContactNo==""){
?><script>history.go(-1);alert('Contact No is required.');</script><?php
}
if(ctype_alpha($ContactNo)){
?><script>history.go(-1);alert('Alphabetic not Allowed in Contact Number');</script><?php
}
if(!check3($ContactNo)){
?><script>history.go(-1);alert('Number with Alphabetic are not allowed in Contact Number');</script><?php
}
include 'InitDB.php';
$result=mysql_query("SELECT * FROM applicants WHERE eMail='$eMail'");
$num=mysql_num_rows($result);
if($num==0){
if(mysql_query("INSERT INTO applicants(LastName,FirstName,MiddleName,eMail,PassWord,Gender,Address,dBirth,CivilStatusID,ContactNo,dApplied) VALUES('$LastName','$FirstName','$MiddleName','$eMail','$PassWord1','$Gender','$Address','$BY-$BM-$BD','$CivilStatusID','$ContactNo',Now())")){
$result=mysql_query("SELECT * FROM applicants WHERE eMail='$eMail' AND PassWord='$PassWord1'");
$num=mysql_num_rows($result);
if($num==1){
session_start();
$_SESSION['ApplicantID']=mysql_result($result,0,'ApplicantID');
header("location: ApplicantResume.php");
}
else{
?><script>alert('Error creating applicant');</script><?php
}
}
else{
?><script>history.go(-1);alert('Error creating applicant');</script><?php
}
}
else{
?><script>history.go(-1);alert('eMail already registered.');</script><?php
}
?>
We need to see the HTML form you are using to submit to this page. Are you sure you have your fields named correctly? If you enter values into every fields, does every field have a value on this post page? Post the HTML that goes along with this page, and it should be easier to diagnose the issue.
It looks like your logic is a bit messed up. The first check says if email is true, show an alert and your second check says if email is not true, also show an alert? Remove the first one imo.
thank you for your reply stoneman and socialexperiment.
@socialexperiment thank you for your advice ill correct my code in email and password now it is work properly this is my revice script but the validation is always stop in email and still accepting an empty password.
<?php
$LastName=$_POST['LastName'];
$FirstName=$_POST['FirstName'];
$MiddleName=$_POST['MiddleName'];
$eMail=$_POST['eMail'];
$PassWord1=$_POST['PassWord1'];
$PassWord2=$_POST['PassWord2'];
$Gender=$_POST['Gender'];
$Address=$_POST['Address'];
$BY=$_POST['BY'];
$BM=$_POST['BM'];
$BD=$_POST['BD'];
$CivilStatusID=$_POST['CivilStatusID'];
$ContactNo=$_POST['ContactNo'];
function check1($string) {
if (preg_match('/[^a-z-A-Z-]/', $string)) {
return false;
} else {
return true;
}
}
function check2($string) {
if(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $string)) {
return false;
} else {
return true;
}
}
function check3($string) {
if(preg_match('/[^0-9-]/',$string)) {
return false;
} else {
return true;
}
}
if($LastName==""){
?><script>history.go(-1);alert('Last name is required.');</script><?php
}
if(strlen($LastName) < 3){
?><script>history.go(-1);alert('Invalid Input in LastName Alphabet should be not less than 3');</script><?php
} elseif (strlen($LastName) >16){
?><script>history.go(-1);alert('Invalid Input in LastName Alphabet should be not more than 16');</script><?php
}
//check if is invalid string
if(ctype_digit($LastName)){
?><script>history.go(-1);alert('Number Are not Allowed in LastName');</script><?php
}
//check if is invalid string
if(!check1($LastName)){
?><script>history.go(-1);alert('Number with Alphabetic Are not allowed in LastName..!!');</script><?php
}
if($FirstName==""){
?><script>history.go(-1);alert('FirstName is required.');</script><?php
}
if(strlen($FirstName) < 3){
?><script>history.go(-1);alert('Invalid input in FirstName Alphabetic should be not less than 3');</script><?php
} elseif (strlen($FirstName) > 16){
?><script>history.go(-1);alert('Invalid input in FirstName Alphabetic Should be not Greater Than 16');</script><?php
}
if(ctype_digit($FirstName)){
?><script>history.go(-1);alert('Number not allowed in FirstName.');</script><?php
}
if(!check1($FirstName)){
?><script>history.go(-1);alert('Number with Alphabetic are not Allowed in FirstName');</script><?php
}
if($MiddleName==""){
?><script>history.go(-1);alert('MiddleName is required.');</script><?php
}
if(strlen($MiddleName) < 3){
?><script>history.go(-1);alert('Invalid input in MiddleName Alphabetic should be not less than 3');</script><?php
}elseif(strlen($MiddleName) > 16){
?><script>history.go(-1);alert('Invalid input in MiddleName Alphabetic should be not less than 16');</script><?php
}
if(ctype_digit($MiddleName)){
?><script>history.go(-1);alert('Number not allowed in MiddleName.');</script><?php
}
if(!check1($MiddleName)){
?><script>history.go(-1);alert('Number with Alphabetic are not Allowed in MiddleName')</script><?php
}
if($eMail==""){
?><script>history.go(-1);alert('eMail is required.');</script><?php
}
if(!check2($eMail)){
?><script>history.go(-1);alert('Invalid Email Address')</script><?php
}
if($PassWord1==""){
?><script>history.go(-1);alert('PassWord is required.');</script><?php
}
if($PassWord1!=$PassWord2){
?><script>history.go(-1);alert('Passwords not the same.');</script><?php
}
if(strlen($PassWord1) < 5){
?><script>history.go(-1);alert('Password Should be Greater Than five')</script><?php
}
if($Address==""){
?><script>history.go(-1);alert('Address is required.');</script><?php
}
if(ctype_digit($Address)){
?><script>history.go(-1);alert('Invalid Address');</script><?php
}
if($ContactNo==""){
?><script>history.go(-1);alert('Contact No is required.');</script><?php
}
if(ctype_alpha($ContactNo)){
?><script>history.go(-1);alert('Alphabetic not Allowed in Contact Number');</script><?php
}
if(!check3($ContactNo)) {
?><script>history.go(-1);alert('Number with Alphabetic are not allowed in Contact number');</script><?php
}
include 'InitDB.php';
$result=mysql_query("SELECT * FROM applicants WHERE eMail='$eMail'");
$num=mysql_num_rows($result);
if($num==0){
if(mysql_query("INSERT INTO applicants(LastName,FirstName,MiddleName,eMail,PassWord,Gender,Address,dBirth,CivilStatusID,ContactNo,dApplied) VALUES('$LastName','$FirstName','$MiddleName','$eMail','$PassWord1','$Gender','$Address','$BY-$BM-$BD','$CivilStatusID','$ContactNo',Now())")){
$result=mysql_query("SELECT * FROM applicants WHERE eMail='$eMail' AND PassWord='$PassWord1'");
$num=mysql_num_rows($result);
if($num==1){
session_start();
$_SESSION['ApplicantID']=mysql_result($result,0,'ApplicantID');
header("location: ApplicantResume.php");
}
}
} else {
?><script>history.go(-1);alert('eMail already registered.');</script><?php
}
?>
stoneman30 wrote:We need to see the HTML form you are using to submit to this page. Are you sure you have your fields named correctly? If you enter values into every fields, does every field have a value on this post page? Post the HTML that goes along with this page, and it should be easier to diagnose the issue.
because when u set error_reporting(E_ALL) (it's recommended when developing), if the post parameter is not exist, there is a notice. so check parameter first;
2.data type
if u want to compare a string with empty string. you should use "===" or strcmp() instead of "==".
3.test your code
the simplest way is write die("xxxx") in you code to test code, until the result is that you hope.
4.simple
why don't u define a function to intead of <script>alert("xxxxx")...
@miki thank you for your reply i correct my mistake in coding just i followed your instruction. thank you very much
this is my revice and finalize script