Jump to content

PHP validation of a form not working!


baxt01

Recommended Posts

hi I have taken the time to learn how to build a form that posts to a database on MySQL using mysqli I had my form working like a dream I then decided that it was time to look at some validation for this form so I used w3scools tutorial and OMG after I added the validation codes into my codes the form vanished I just get a blank page no text or text area's at all now I know already I have done something wrong it always is,

so here is my codes after I add the validation:

<?php    if (isset($_POST['submit'] ) ) {        $host_name  = "localhost";        $database   = "mnvbcou1_simple_login";        $user_name  = "mnvbcou1_mike";        $password   = "KaiSkye14";                  $db = mysqli_connect( $host_name, $user_name, $password, $database );                     if (!$db)           {               die("Failed to connect to MySQL: " . mysql_error());           }                // example of inserting data into that table:         $sql = "INSERT INTO simple_login(fname, lname, gender, address, contact, picture, username, password) "              . " VALUES( ?, ?, ?, ?, ?, ?, ?, ? )";                 $stmt = $db->prepare( $sql );         if (!$stmt)         {             die("Failed to prepare statement: " . $sql);         }                 // Get Values        $fname=$_POST['fname'];        $lname=$_POST['lname'];        $mname=$_POST['mname'];        $address=$_POST['address'];        $contact=$_POST['contact'];        $pic=$_POST['pic'];        $username=$_POST['username'];        $password=$_POST['password'];                $stmt->bind_param("ssss", $fname, $lname, $mname, $address, $contact, $pic, $username, $password);                 if ( ! $stmt->execute() )         {             die("Execution of bound statement failed: " . $stmt->error);         }                echo "Inserted {$stmt->affected_rows} correctly.<hr/>";                 $db->close();    }?><!doctype html><html>    <head>        <meta charset="utf-8">        <title>Registration Form</title><style>.error {color: #FF0000;}</style>    </head>        <body>    <?php// define variables and set to empty values$fnameErr = $lnameErr = $mnameErr = $addressErr = $contactErr = $usernameErr = $pasword = "";$fname = $lname = $mname = $address = $contact = $username = $pasword = "";if ($_SERVER["REQUEST_METHOD"] == "POST") {   if (empty($_POST["fname"])) {     $fnameErr = "First Name is required";   } else {     $fname = test_input($_POST["fname"]);     // check if first name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z ]*$/",$fname)) {       $fnameErr = "Only letters and white space allowed";      }   }      if (empty($_POST["lname"])) {     $lnameErr = "Last Name is required";   } else {     $lname = test_input($_POST["lname"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z ]*$/",$lname)) {       $lnameErr = "Only letters and white space allowed";      }   }   if (empty($_POST["mname"])) {     $mnameErr = "Gender is required";   } else {     $mname = test_input($_POST["mname"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z ]*$/",$mname)) {       $mnameErr = "Only letters and white space allowed";      }   }   if (empty($_POST["address"])) {     $addressErr = "Address is required";   } else {     $address = test_input($_POST["address"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z0-9 ]*$/",$address)) {       $addressErr = "Only letters numbers and white space allowed";      }   }   if (empty($_POST["contact"])) {     $contactErr = "Contact Number is required";   } else {     $contact = test_input($_POST["contact"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[0-9 ]*$/",$contact)) {       $contactErr = "Only numbers and white space allowed";      }   }   if (empty($_POST["username"])) {     $usernameErr = "user Name is required";   } else {     $username = test_input($_POST["username"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z0-9 ]*$/",$username)) {       $usernameErr = "Only letters numbers and white space allowed";      }   }   if (empty($_POST["pasword"])) {     $paswordErr = "Pasword is required";   } else {     $paswrod = test_input($_POST["lname"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z0-9]*$/",$pasword)) {       $paswrodErr = "Only letters and numbers allowed";      }   }function test_input($data) {   $data = trim($data);   $data = stripslashes($data);   $data = htmlspecialchars($data);   return $data;}?>        <form name="reg" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"  method="post">            <table width="274" border="0" align="center" cellpadding="2" cellspacing="0">                <tr>                    <td width="95"><div align="right">First Name:</div></td>                    <td width="171"><input type="text" name="fname" /></td>   <span class="error">* <?php echo $fnameErr;?></span>                </tr>                <tr>                    <td><div align="right">Last Name:</div></td>                    <td><input type="text" name="lname" /></td>   <span class="error">* <?php echo $lnameErr;?></span>                </tr>                <tr>                    <td><div align="right">Gender:</div></td>                    <td><input type="text" name="mname" /></td>   <span class="error">* <?php echo $mnameErr;?></span>                </tr>                <tr>                    <td><div align="right">Address:</div></td>                    <td><input type="text" name="address" /></td>   <span class="error">* <?php echo $addressErr;?></span>                </tr>                <tr>                    <td><div align="right">Contact No.:</div></td>                    <td><input type="text" name="contact" /></td>   <span class="error">* <?php echo $contactErr;?></span>                </tr>                <tr>                    <td><div align="right">Picture:</div></td>                    <td><input type="text" name="pic" /></td>   <span class="error">* <?php echo $picErr;?></span>                </tr>                <tr>                    <td><div align="right">Username:</div></td>                    <td><input type="text" name="username" /></td>   <span class="error">* <?php echo $usernameErr;?></span>                </tr>                <tr>                    <td><div align="right">Password:</div></td>                    <td><input type="text" name="password" /></td>   <span class="error">* <?php echo $paswordErr;?></span>                </tr>                <tr>                    <td><div align="right"></div></td>                    <td><input name="submit" type="submit" value="Submit" /></td>                </tr>            </table>        </form>    </body></html> 
Link to comment
Share on other sites

Your server is set to not display PHP errors. If you put this at the beginning of your file you should see error messages that tell you why the code isn't working:

ini_set('display_errors', 1);

The reason it's not working is that this if() statement doesn't have a closing brace:

if ($_SERVER["REQUEST_METHOD"] == "POST") {

Another problem in your code is that you've misspelled "password" in this section of your code:

if (empty($_POST["pasword"])) {    $paswordErr = "Pasword is required";} else {    $paswrod = test_input($_POST["lname"]);    // check if last name only contains letters and whitespace    if (!preg_match("/^[a-zA-Z0-9]*$/",$pasword)) {        $paswrodErr = "Only letters and numbers allowed";    }}
  • Like 1
Link to comment
Share on other sites

 

Your server is set to not display PHP errors. If you put this at the beginning of your file you should see error messages that tell you why the code isn't working:

ini_set('display_errors', 1);

The reason it's not working is that this if() statement doesn't have a closing brace:

if ($_SERVER["REQUEST_METHOD"] == "POST") {

Another problem in your code is that you've misspelled "password" in this section of your code:

if (empty($_POST["pasword"])) {    $paswordErr = "Pasword is required";} else {    $paswrod = test_input($_POST["lname"]);    // check if last name only contains letters and whitespace    if (!preg_match("/^[a-zA-Z0-9]*$/",$pasword)) {        $paswrodErr = "Only letters and numbers allowed";    }}

after I read your post I had to give myself a slap for not adding that error checking as I have been told about it before hey hoe its 2 am here lol

ok so I added the error checking and corrected the silly typos and my form re appeared leaving these 2 error messages

 

 

Warning: mysqli_connect(): Headers and client library minor version mismatch. Headers:50540 Library:100016 in /home/mnvbcou1/public_html/index1.php on line 9Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables in /home/mnvbcou1/public_html/index1.php on line 36Execution of bound statement failed: No data supplied for parameters in prepared statement

 

ok so here is my code down to line 9

<?phpini_set('display_errors', 1);    if (isset($_POST['submit'] ) ) {        $host_name  = "localhost";        $database   = "mnvbcou1_simple_login";        $user_name  = "mnvbcou1_mike";        $password   = "KaiSkye14";                  $db = mysqli_connect( $host_name, $user_name, $password, $database );   

and here is 36

        $stmt->bind_param("ssss", $fname, $lname, $mname, $address, $contact, $pic, $username, $password); 
Link to comment
Share on other sites

I did a quick search for your first error message and this is what I found: http://stackoverflow.com/questions/10759334/headers-and-client-library-minor-version-mismatch

 

As for the error on line 36, you need as many characters in the string ("ssss") as you have variables. In your case it would be "ssssssss", unless you want one of the variables to be an integer, floating point number or binary data.

Link to comment
Share on other sites

i hear ya on the ssss I only added that error on here to show what was been thrown back but had already corrected as I fell into deep zzzZZZZZZ land tehe

anyhow now is a fresh day bring yet another new set of errors and more mud to throw at my mental fan :)

now the line issue is fixed with the array not having enough sss in i re mention the error researched on stack overflow above,

from what I read this issue is way beyond my control on my server the PHP and MySQL versions and install are down to my system admin its not something I can change from my control panel I can view config data but not change so I will be sending a sharp email their way :)

 

ok so for this moment lets move onwards and upwards with this code set of errors

this next error been returned to me now I think I kind of know what its saying and maybe even why but how to fix im not as sure about so im hoping you guys / girls can confirm or correct my thoughts here:

here is the error:

 

Fatal error: Call to undefined function test_input() in /home/mnvbcou1/public_html/index1.php on line 69

61. // define variables and set to empty values62.$fnameErr = $lnameErr = $mnameErr = $addressErr = $contactErr = $usernameErr = $password = "";63.$fname = $lname = $mname = $address = $contact = $username = $password = "";64.65. if ($_SERVER["REQUEST_METHOD"] == "POST") {66.   if (empty($_POST["fname"])) {67.     $fnameErr = "First Name is required";68.   } else {69.     $fname = test_input($_POST["fname"]);

ok so now if I re show the codes as a whole I can explain what I think is the issue,

<?phpini_set('display_errors', 1);    if (isset($_POST['submit'] ) ) {        $host_name  = "localhost";        $database   = "mnvbcou1_simple_login";        $user_name  = "mnvbcou1_mike";        $password   = "KaiSkye14";                  $db = mysqli_connect( $host_name, $user_name, $password, $database );                     if (!$db)           {               die("Failed to connect to MySQL: " . mysql_error());           }                // example of inserting data into that table:         $sql = "INSERT INTO simple_login(fname, lname, gender, address, contact, picture, username, password) "              . " VALUES( ?, ?, ?, ?, ?, ?, ?, ? )";                 $stmt = $db->prepare( $sql );         if (!$stmt)         {             die("Failed to prepare statement: " . $sql);         }                 // Get Values        $fname=$_POST['fname'];        $lname=$_POST['lname'];        $mname=$_POST['mname'];        $address=$_POST['address'];        $contact=$_POST['contact'];        $pic=$_POST['pic'];        $username=$_POST['username'];        $password=$_POST['password'];                $stmt->bind_param("ssssssss", $fname, $lname, $mname, $address, $contact, $pic, $username, $password);                 if ( ! $stmt->execute() )         {             die("Execution of bound statement failed: " . $stmt->error);         }                echo "Inserted {$stmt->affected_rows} correctly.<hr/>";                 $db->close();    }?><!doctype html><html>    <head>        <meta charset="utf-8">        <title>Registration Form</title><style>.error {color: #FF0000;}</style>    </head>        <body>    <?php// define variables and set to empty values$fnameErr = $lnameErr = $mnameErr = $addressErr = $contactErr = $usernameErr = $password = "";$fname = $lname = $mname = $address = $contact = $username = $password = "";if ($_SERVER["REQUEST_METHOD"] == "POST") {   if (empty($_POST["fname"])) {     $fnameErr = "First Name is required";   } else {     $fname = test_input($_POST["fname"]);     // check if first name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z ]*$/",$fname)) {       $fnameErr = "Only letters and white space allowed";      }   }      if (empty($_POST["lname"])) {     $lnameErr = "Last Name is required";   } else {     $lname = test_input($_POST["lname"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z ]*$/",$lname)) {       $lnameErr = "Only letters and white space allowed";      }   }   if (empty($_POST["mname"])) {     $mnameErr = "Gender is required";   } else {     $mname = test_input($_POST["mname"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z ]*$/",$mname)) {       $mnameErr = "Only letters and white space allowed";      }   }   if (empty($_POST["address"])) {     $addressErr = "Address is required";   } else {     $address = test_input($_POST["address"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z0-9 ]*$/",$address)) {       $addressErr = "Only letters numbers and white space allowed";      }   }   if (empty($_POST["contact"])) {     $contactErr = "Contact Number is required";   } else {     $contact = test_input($_POST["contact"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[0-9 ]*$/",$contact)) {       $contactErr = "Only numbers and white space allowed";      }   }   if (empty($_POST["username"])) {     $usernameErr = "user Name is required";   } else {     $username = test_input($_POST["username"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z0-9 ]*$/",$username)) {       $usernameErr = "Only letters numbers and white space allowed";      }   }   if (empty($_POST["password"])) {     $passwordErr = "Pasword is required";   } else {     $passwrod = test_input($_POST["lname"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z0-9]*$/",$password)) {       $passwrodErr = "Only letters and numbers allowed";      }   }function test_input($data) {   $data = trim($data);   $data = stripslashes($data);   $data = htmlspecialchars($data);   return $data;}}?>        <form name="reg" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"  method="post">            <table width="274" border="0" align="center" cellpadding="2" cellspacing="0">                <tr>                    <td width="95"><div align="right">First Name:</div></td>                    <td width="171"><input type="text" name="fname" /></td>   <span class="error">* <?php echo $fnameErr;?></span>                </tr>                <tr>                    <td><div align="right">Last Name:</div></td>                    <td><input type="text" name="lname" /></td>   <span class="error">* <?php echo $lnameErr;?></span>                </tr>                <tr>                    <td><div align="right">Gender:</div></td>                    <td><input type="text" name="mname" /></td>   <span class="error">* <?php echo $mnameErr;?></span>                </tr>                <tr>                    <td><div align="right">Address:</div></td>                    <td><input type="text" name="address" /></td>   <span class="error">* <?php echo $addressErr;?></span>                </tr>                <tr>                    <td><div align="right">Contact No.:</div></td>                    <td><input type="text" name="contact" /></td>   <span class="error">* <?php echo $contactErr;?></span>                </tr>                <tr>                    <td><div align="right">Picture:</div></td>                    <td><input type="text" name="pic" /></td>   <span class="error">* <?php echo $picErr;?></span>                </tr>                <tr>                    <td><div align="right">Username:</div></td>                    <td><input type="text" name="username" /></td>   <span class="error">* <?php echo $usernameErr;?></span>                </tr>                <tr>                    <td><div align="right">Password:</div></td>                    <td><input type="text" name="password" /></td>   <span class="error">* <?php echo $paswordErr;?></span>                </tr>                <tr>                    <td><div align="right"></div></td>                    <td><input name="submit" type="submit" value="Submit" /></td>                </tr>            </table>        </form>    </body></html> 

I think this code is referring to the fact that the function call on line 69 is defined on line 136 maybe im just guessing with this but that's my best efforts on this

Link to comment
Share on other sites

Moving the function test_input() outside of the if() statement solves the problem.

 

I am getting some other errors. Some errors are probably not showing up for you because they're a lower level. To make sure all errors are visible, add this at the top of your page:

error_reporting(E_ALL);

The first error I'm getting is that you forgot to define $passwordErr and instead defined $password twice. The other one is that the variable $picErr wasn't defined.

  • Like 1
Link to comment
Share on other sites

that was the missing line yep that was everything I needed right there LOL

ok seriously though that just took me around 30 - 40 minutes of re - ordering spell checking

AND

finally that whole code does execute pretty perfectly!

we have only 2 more things to ask of anyone who can help lol

just looking at my TEST + Err system there is not any line there to tell the code to end before posting the incorrect data to my DB

in my code it has a double IF check on the same field of the form first IF empty msg required field

secondly check field content format preg match

if ($_SERVER["REQUEST_METHOD"] == "POST") {   if (empty($_POST["fname"])) {     $fnameErr = "First Name is required";   } else {     $fname = test_input($_POST["fname"]);     // check if first name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z ]*$/",$fname)) {       $fnameErr = "Only letters and white space allowed";      }   }

I was thinking would it word to add to this else / if statement 2 more else's or if's almost a repeat of what is there now but in replace of the fnameErr = msg change this to = EXIT type of thing?so that the php never posts the data it just stops or even goes back to the form

if my thinking is on the right track I think I will try it but sometimes I try it break it and then am told I went all wrong way about it lol

Link to comment
Share on other sites

You need to do all the validation before putting the data into the database.

 

After all the validation is done, if no errors were found, then you run the query.

Link to comment
Share on other sites

yes this is one of them moments where im sat here feeling rather stupid,

that moment where I have had a nights sleep and come back to it and read your comment looked down my codes thinking OMG what was I thinking coding is always set out by logical argument order of execution and I told the code to post form data to DB before I validate the $_POSt data that should be an easy fix then

Link to comment
Share on other sites

HAHAHAHA that is just too funny!

after my last comment to you as I said it should have been a easy fix problem well maybe for anyone else in the world perhaps............

I went to my codes figured I do not need to make a back up seen as I am not changing my codes im just re arranging them so I did it live

I went onto my server and used copy and paste to re organise the codes so that my DB connect was at the end and my form was at the start leaving the validation codes in the middle

sounds ok so far so I saved the work and loaded the page and well im now getting HTTP 500 internal server error im really not sure what exactly happened but it seems the server does not agree with the order of my codes............

 

so feel free to join me in starting over here is what I have that's giving me my HTTP 500 error:

<html>    <head>        <meta charset="utf-8">        <title>Registration Form</title><style>.error {color: #FF0000;}</style>    </head>    <body>            <form name="reg" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"  method="post">            <table width="274" border="0" align="center" cellpadding="2" cellspacing="0">                <tr>                    <td width="95"><div align="right">First Name:</div></td>                    <td width="171"><input type="text" name="fname" />   <span class="error">* <?php echo $fnameErr;?></span></td>                </tr>                <tr>                    <td><div align="right">Last Name:</div></td>                    <td><input type="text" name="lname" />   <span class="error">* <?php echo $lnameErr;?></span></td>                </tr>                <tr>                    <td><div align="right">Gender:</div></td>                    <td><input type="text" name="mname" />   <span class="error">* <?php echo $mnameErr;?></span></td>                </tr>                <tr>                    <td><div align="right">Address:</div></td>                    <td><input type="text" name="address" />   <span class="error">* <?php echo $addressErr;?></span></td>                </tr>                <tr>                    <td><div align="right">Contact No.:</div></td>                    <td><input type="text" name="contact" />   <span class="error">* <?php echo $contactErr;?></span></td>                </tr>                <tr>                    <td><div align="right">Picture:</div></td>                    <td><input type="text" name="pic" />   <span class="error">* <?php echo $picErr;?></span></td>                </tr>                <tr>                    <td><div align="right">Username:</div></td>                    <td><input type="text" name="username" />   <span class="error">* <?php echo $usernameErr;?></span></td>                </tr>                <tr>                    <td><div align="right">Password:</div></td>                    <td><input type="text" name="password" />                       <span class="error">* <?php echo $passwordErr;?></span></td>                </tr>                <tr>                    <td><div align="right"></div></td>                    <td><input name="submit" type="submit" value="Submit" /></td>                </tr>            </table>        </form>    </body>    </html>        <?php    // define variables and set to empty values$fnameErr = $lnameErr = $mnameErr = $addressErr = $contactErr = $picErr = $usernameErr = $passwordErr = "";$fname = $lname = $mname = $address = $contact = $pic = $username = $password = "";if ($_SERVER["REQUEST_METHOD"] == "POST") {   if (empty($_POST["fname"])) {     $fnameErr = "First Name is required";   } else {     $fname = test_input($_POST["fname"]);     // check if first name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z ]*$/",$fname)) {       $fnameErr = "Only letters and white space allowed";      }   }      if (empty($_POST["lname"])) {     $lnameErr = "Last Name is required";   } else {     $lname = test_input($_POST["lname"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z ]*$/",$lname)) {       $lnameErr = "Only letters and white space allowed";      }   }   if (empty($_POST["mname"])) {     $mnameErr = "Gender is required";   } else {     $mname = test_input($_POST["mname"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z ]*$/",$mname)) {       $mnameErr = "Only letters and white space allowed";      }   }   if (empty($_POST["address"])) {     $addressErr = "Address is required";   } else {     $address = test_input($_POST["address"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z0-9 ]*$/",$address)) {       $addressErr = "Only letters numbers and white space allowed";      }   }   if (empty($_POST["contact"])) {     $contactErr = "Contact Number is required";   } else {     $contact = test_input($_POST["contact"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[0-9 ]*$/",$contact)) {       $contactErr = "Only numbers and white space allowed";      }   }   if (empty($_POST["pic"])) {     $picErr = "user Name is required";   } else {     $pic = test_input($_POST["pic"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z0-9 ]*$/",$pic)) {       $picErr = "Only letters numbers and white space allowed";      }   }   if (empty($_POST["username"])) {     $usernameErr = "user Name is required";   } else {     $username = test_input($_POST["username"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z0-9 ]*$/",$username)) {       $usernameErr = "Only letters numbers and white space allowed";      }   }   if (empty($_POST["password"])) {     $passwordErr = "Pasword is required";   } else {     $passwrod = test_input($_POST["lname"]);     // check if last name only contains letters and whitespace     if (!preg_match("/^[a-zA-Z0-9]*$/",$password)) {       $passwrodErr = "Only letters and numbers allowed";      }   }}function test_input($data) {   $data = trim($data);   $data = stripslashes($data);   $data = htmlspecialchars($data);   return $data;}    if (isset($_POST['submit'] ) ) {        $host_name  = "localhost";        $database   = "mnvbcou1_simple_login";        $user_name  = "mnvbcou1_mike";        $password   = "KaiSkye14";                  $db = mysqli_connect( $host_name, $user_name, $password, $database );                     if (!$db)           {               die("Failed to connect to MySQL: " . mysql_error());           }                // example of inserting data into that table:         $sql = "INSERT INTO simple_login(fname, lname, gender, address, contact, picture, username, password) "              . " VALUES( ?, ?, ?, ?, ?, ?, ?, ? )";                 $stmt = $db->prepare( $sql );         if (!$stmt)         {             die("Failed to prepare statement: " . $sql);         }         // Get Values        $fname=$_POST['fname'];        $lname=$_POST['lname'];        $mname=$_POST['mname'];        $address=$_POST['address'];        $contact=$_POST['contact'];        $pic=$_POST['pic'];        $username=$_POST['username'];        $password=$_POST['password'];                $stmt->bind_param("ssssssss", $fname, $lname, $mname, $address, $contact, $pic, $username, $password);                 if ( ! $stmt->execute() )         {             die("Execution of bound statement failed: " . $stmt->error);         }                echo "Inserted {$stmt->affected_rows} correctly.<hr/>";                 $db->close();?>

sorry to be a pain in the butt

Link to comment
Share on other sites

Ok i think i just seen some errors with how i have laid my codes out meaning it will not work as i have changed the variable names while the code validates so the stm call is now invalid also the section where i call the post values in the db conect code is still trying to call the orignal post values not the validated version so it becomes pointless * sigh * i will look when i get home from work i cant edit code from the iphone lol

Edited by baxt01
Link to comment
Share on other sites

ok with a busy weekend with the kids I have now had the chance to sit and work out what was wrong in my coding and it is working again ( well kind of )

my page now loads again

the form is there showing signs of validation presence

on submit although the validation is showing up it is still posting data to my DB even if the content is not valid

the odes say if field * is empty give error message

but I can not work out how to make the code end or stop when there is an error

I was wondering would something like:

 

 

if ( ! $fname->valid() )        {            die("field First Name incorret: " . $fname->error);        }

 

obviously some changes but in principal would that type of code on the end of each field test in my form work?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...