Help me with my php form

Hi Everybody,

i am a php/mysql newbie and i am trying to create form to send data into db. here are the condition i want to meet:
1-data should go to db only when all fiels are filled
2- prevent script from running when conditions are met

here is my code:

"> " /> * <?php echo $fnameError;?>

" /> * <?php echo $surnameError;?>

[b]PHP PART[/b]
<?php $first_name = $sur_name = ""; $fnameError = $surnameError =""; if ($_SERVER["REQUEST_METHOD"]== "POST") { function clean_input_provide ($value){ $value = trim($value); $value = htmlspecialchars($value); $value = stripslashes($value); return ($value); } if (empty($_POST["fname"])) { $fnameError = "Please enter your first name"; } else { $first_name = clean_input_provide($_POST["fname"]); if (!preg_match("/^[a-zA-Z ]*$/", $first_name)) { $fnameError = "Only letters and white space allowed"; } } if (empty($_POST["surname"])) { $surnameError = "Please enter your surname"; } else { $sur_name = clean_input_provide($_POST["surname"]); if (!preg_match("/^[a-zA-Z ]*$/", $sur_name)) { $surnameError = "Only letters and white space allowed"; } } if (!empty($first_name&&$sur_name&&$password&&$address)) { $sql = "INSERT INTO tbl_address_book (First_Name, Surname, Address, Password) VALUES ('$first_name', '$sur_name', '$address', '$password')"; if (mysqli_query($db_connection, $sql)) { echo "Recorded added"; } else { echo "No records"; } } } ?>

My problem is, i want to prevent the script from running when the preg_match condition is met

Thanks

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories