This code doesnt get into the if statements to check the conditions. Please help me find what is wrong with it.

<?php

$info="";
if (isset($_POST['RegButton']))
{
    $FirstName= $_POST['Fname'];
    $LastName= $_POST['Lname'];
    $Email= $_POST['Email'];
    $Phone= $_POST['Phone'];
    $userPass= $_POST['password'];
    $repass= $_POST['repassword'];

//For password encryption
    $slt= time();   
    $salt= $slt;
    $harshed= sha1($userPass.$salt);
if (empty($_POST['Fname'])){
        $info= "The first name field cannot be blank!, Please fill all blanks";
}elseif (empty($_POST['Lname'])){
    $info= "The last name field cannot be blank!, Please fill all blanks";
}elseif (empty($_POST['Email'])){
    $info= "The email field cannot be blank!, Please fill all blanks";  
}elseif (empty($_POST['Phone'])){
    $info= "The phone number field cannot be blank!, Please fill all blanks";
}elseif (!is_numeric($_POST['Phone'])){
    $info= "You've not entered a phone Number";
}elseif ($userPass != $repass){
    $info= "Password does not match";
}
if(!filter_var($_POST['Email'], FILTER_VALIDATE_EMAIL)){
        $info= "Invalid Email Address";
}

include ("conn.php");
if (!empty($_POST['Fname']) && !empty($_POST['Lname']) && !empty($_POST['Email']) && !empty($_POST['Phone'])){
$sql= "INSERT INTO tbreg (Firstname, Lastname,Email, phone,salt, harshed) VALUES ('$FirstName', '$LastName', '$Email', '$Phone','$salt','$harshed')";

$result= mysql_query($sql);

 if ($result=1)
    {
    $info= "Succesfully Saved!, You will receive an email containning your login credentials and an activation link to activate your email.";
    }else
    {
    $info= "There was an during submission";
    }
}
}

?>

Recommended Answers

All 8 Replies

Member Avatar for iamthwee

if it doesn't get to the if statements try doing a few echos to find out why.

line 40 should be == not =

testing if fields are blank should come before manipulating those fields

@almostbob, i still dont understand what you mean, and have replaced the = with == on line 40, its still now checking the conditions, it still submits to the database even when the phone number field isnt numeric.

after all determinatins of error message
if(!filter_var($_POST['Email'], FILTER_VALIDATE_EMAIL)){$info= "Invalid Email Address";}
there is no exit point\
nothing tells the code to skip inserting the data into the database if there is an error that populates $info
35.if (!empty($_POST['Fname']) && !empty($_POST['Lname']) && !empty($_POST['Email']) && !empty($_POST['Phone'])){}
this is already accomplished above, the code checks the column data is not blank and does basic validation earlier, so
35.if (!$info){}

if (empty($_POST['Fname'])){ $info= "The first name field cannot be blank!, Please fill all blanks";}
if (empty($_POST['Lname'])){ $info= ."The last name field cannot be blank!, Please fill all blanks";}
if (empty($_POST['Email'])){ $info= ."The email field cannot be blank!, Please fill all blanks";}
if (empty($_POST['Phone'])){ $info= ."The phone number field cannot be blank!, Please fill all blanks";}
if (!is_numeric($_POST['Phone'])){ $info= ."You've not entered a phone Number";}
if ($userPass != $repass){ $info= ."Password does not match";}
if(!filter_var($_POST['Email'], FILTER_VALIDATE_EMAIL)){ $info= ."Invalid Email Address";}

ensures that the user is given all errors in each input
I didnt bother putting the carriage return/newline in each error line.
(didnt think of it till late)

Thanks for your help, but please im a newbie in php so my question might sound as such. Please can you really just tell me how to fix the problem? Are you saying i should enclose all the IF conditions in the if(!$info){}?. Is that what you mean, if not then what?

the op code line35, is functionally useless
the op code already examines the content of the $_post variables, and assigns a value to $info if they are not correct.
.If $info is not nul, do not continue to add the data to the table
, replace line 35 with the new line 35 (up to the final opening brace)

the seven lines of validation post6 in this thread, are to replace the op code line17 to line31, to issue all validation messages, if multiple fields are incorrect

Thanks.. I solved the problem..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.