Error Messages are not displying in PHP for validation - php

Following is the PHP code
Database file working fine.
if(isset($_POST['submit']))
{
$error = array();
if(empty($_POST["fname"]))
{
$error[] = "Please Enter a name";
}
else
{
$fname = $_POST["fname"];
}
if(empty($_POST["lname"]))
{
$error[] = "Please Enter last name";
}
else
{
$lname = $_POST["lname"];
}
if(empty($_POST["email"]))
{
$error = "Enter email Id";
}
else
{
if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*#([a-zA-Z0-9_-])+([a-zA-Z0- 9\._-]+)+$/", $_POST["email"]))
{
$email = $_POST["email"];
}
else
{
$error = "Enter a vaild Email Id";
}
}
if(empty($_POST["password"]))
{
$error = "Enter a password";
}
else
{
$password = $_POST["password"];
}
if(!empty($error))
{
$sql = "SELECT * FROM form (id, 'FirstName', 'LastName', 'Email', 'Password') VALUES('', '$fname', '$lname', '$email', '$password')";
$result = mysql_query($sql);
echo "Successfully Register";
}
else
{
foreach($error as $key => $values)
{
echo ' <li>' . $values . '</li>';
}
echo '</ol>';
echo "Error";
}
}
?>
The above code is not displying any error messages... if i submit the form only blank page ll appear... I validate my form using above code but it is just a basic method I used and by using for each I'm displaying errors...

the following test is wrong :
if(!empty($error))
should be :
if(empty($error))
And your SQL is wrong too... should be :
$sql = "Insert into form (FirstName, LastName, Email, Password) VALUES('$fname', '$lname', '$email', '$password')";
supposing your id field is auto-incremented

You forget to push the errors to array. You have
$error = "Enter a password"; //$error is no more an array. It is a string
And must be in several places:
$error[] = "Enter a password";
Also, I recommend you using nested if statements:
if (!empty($_POST['submit'])){
$errors = array() ;
if (!isset($_POST['email'])
$errors['email'] = "No email" ;
//And so on.
//Then check for errors
if (!empty($errors)){
//proceed submission
}
}

Try This code, it will works fine for you.
<?php
if(isset($_POST['submit']))
{
$error = array();
if(empty($_POST["fname"]))
{
$error[] = "Please Enter a name";
}
else
{
$fname = $_POST["fname"];
}
if(empty($_POST["lname"]))
{
$error[] = "Please Enter last name";
}
else
{
$lname = $_POST["lname"];
}
if(empty($_POST["email"]))
{
$error[] = "Enter email Id";
}
else
{
if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*#([a-zA-Z0-9_-])+([a-zA-Z0- 9\._-]+)+$/", $_POST["email"]))
{
$email = $_POST["email"];
}
else
{
$error[] = "Enter a vaild Email Id";
}
}
if(empty($_POST["password"]))
{
$error[] = "Enter a password";
}
else
{
$password = $_POST["password"];
}
if(count($error)<=0)
{
$sql = "SELECT * FROM form (id, 'FirstName', 'LastName', 'Email', 'Password') VALUES('', '$fname', '$lname', '$email', '$password')";
$result = mysql_query($sql);
echo "Successfully Register";
}
else
{
foreach($error as $key => $values)
{
echo ' <li>' . $values . '</li>';
}
echo '</ol>';
echo "Error";
}
}
?>

Related

Register new user - Problem with SQLSTATE

Implementing a simple register system and after implementing try to test it I get this error message:
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
My code for register user is:
<?php
session_start();
require_once('config.php');
if(isset($_POST['submit']))
{ if(isset($_POST['name'],$_POST['lastname'],$_POST['email'],$_POST['pass']) && !empty($_POST['name']) && !empty($_POST['lastname']) && !empty($_POST['email']) && !empty($_POST['pass']))
{
$name= trim($_POST['name']);
$lastname = trim($_POST['lastname']);
$email= trim($_POST['email']);
$pass= trim($_POST['pass']);
$options = array("cost"=>4);
$hashPassword = password_hash($pass,PASSWORD_BCRYPT,$options);
$date = date('Y-m-d H:i:s');
if(filter_var($email, FILTER_VALIDATE_EMAIL))
{
$sql = 'SELECT * FROM members WHERE email = :email';
$stmt = $pdo->prepare($sql);
$p = ['email'=>$email];
$stmt->execute($p);
if($stmt->rowCount() == 0)
{
$sql = "insert into members (name, lastname, email, `pass`, created_date,updated) values(:name,:lastname,:email,:pass,:created_date,:updated)";
try{
$handle = $pdo->prepare($sql);
$params = [
':name'=>$name,
':lastname'=>$lastname,
':email'=>$email,
':pass'=>$hashPassword,
':created_date'=>$date,
':updated'=>$date
];
$handle->execute($params);
$success = 'Successfull registration!';
}
catch(PDOException $e){
$errors[] = $e->getMessage();
}
}
else
{
$valName= $name;
$valLastname= $lastname;
$valEmail= '';
$valPass= $pass;
$errors[] = 'Email address already registered';
}
}
else
{
$errors[] = "Email address is not valid";
}
}
else
{
if(!isset($_POST['name']) || empty($_POST['name']))
{
$errors[] = 'Error 1!';
}
else
{
$valIme= $_POST['name'];
}
if(!isset($_POST['lastname']) || empty($_POST['lastname']))
{
$errors[] = 'Error 2!';
}
else
{
$valLastname= $_POST['lastname'];
}
if(!isset($_POST['email']) || empty($_POST['email']))
{
$errors[] = 'Error 4!';
}
else
{
$valEmail= $_POST['email'];
}
if(!isset($_POST['pass']) || empty($_POST['pass']))
{
$errors[] = 'Error 5!';
}
else
{
$valPass= $_POST['pass'];
}
}
}
?>
I don't get where the problem could be. I think is that I need to change the date value inserted to the database, and that could be a problem. Can someone test this code and tell me where is the problem?

PDO sql insert not executing and not showing error

So this is my second project with PDO and after checking with my first project I can not for the life of me figure out why this INSERT is not working and I am not getting an error message. This is the firs time I am using PDO inside of sublime 3. Don't think this has anything to do with it just figured Id add that.
Here is my connection which is giving me no problems but here just in case!
<?php
$connString = "mysql:host=localhost;dbname=rmldb";
$uname = "root";
$pwd = "DB_PASS";
try{
$pdo = new PDO($connString, $uname, $pwd);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $e){
echo "Connection failed: " . $e->getMessage();
}?>
Here is my php with the query:
I checked to see if I was making it to the try/catch by adding an echo and I am getting all the way through to the end of the 'try' block but still nothing is being inserted and I cannot figure out why.
if($_SERVER["REQUEST_METHOD"] == "POST"){
$formdata['fname'] = trim($_POST['fname']);
$formdata['lname'] = trim($_POST['lname']);
$formdata['email'] = trim($_POST['email']);
$formdata['pwd'] = trim($_POST['pwd']);
$formdata['pwd2'] = trim($_POST['pwd2']);
$formdata['phone'] = trim($_POST['phone']);
$formdata['date'] = $_POST['dateCreated'];
//Checking for empty form values
if(empty($formdata['fname'])){
$err = 1;
$errfname = "First name is required";
}
if(empty($formdata['lname'])){
$err = 1;
$errlname = "Last name is required";
}
if(empty($formdata['email'])){
$err = 1;
$erremail = "Email is required";
}
if(empty($formdata['pwd'])){
$err = 1;
$errpwd = "Please enter a password";
}
if(empty($formdata['pwd2'])){
$err = 1;
$errpwd2 = "Please enter a password";
}
if(empty($formdata['phone'])){
$formdata['phone'] = "N/A";
}
//Checking for matching password values
if($formdata['pwd'] != $formdata['pwd2']){
$err = 1;
$errpwd = "Passwords do not match";
$errpwd2 = "Passwords do not match";
}
//Checking for existing emails
try{
$sql = "INSERT INTO users (fname, lname, email, pwd, phone, dateCreated, admin) VALUES (:fname, :lname, :email, :pwd, :phone, :dateCreated, :admin)";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(":fname", $formdata['fname']);
$stmt->bindValue(":lname", $formdata['lname']);
$stmt->bindValue(":email", $formdata['email']);
$stmt->bindValue(":pwd", $formdata['pwd']);
$stmt->bindValue(":phone", $formdata['phone']);
$stmt->bindValue(":dateCreated", $rightnow);
$stmt->bindValue(":admin", 0);
$stmt->execute();
$showform = 0;
echo "<p class='error'> Recorded!</p>";
}catch(PDOException $e){
$e->getMessage();
}
}
This may not be the best way to do it but this should get you what you want.
<?php
$formdata['fname'] = trim($_POST['fname']);
$formdata['lname'] = trim($_POST['lname']);
$formdata['email'] = trim($_POST['email']);
$formdata['pwd'] = trim($_POST['pwd']);
$formdata['pwd2'] = trim($_POST['pwd2']);
$formdata['phone'] = trim($_POST['phone']);
$formdata['date'] = $_POST['dateCreated'];
//Checking for empty form values
if (empty($formdata['fname'])) {
$err = 1;
$errfname = "First name is required";
} else if (empty($formdata['lname'])) {
$err = 1;
$errlname = "Last name is required";
} else if (empty($formdata['email'])) {
$err = 1;
$erremail = "Email is required";
} else if (empty($formdata['pwd'])) {
$err = 1;
$errpwd = "Please enter a password";
} else if (empty($formdata['pwd2'])) {
$err = 1;
$errpwd2 = "Please enter a password";
} else if (empty($formdata['phone'])) {
$formdata['phone'] = "N/A";
} else if ($formdata['pwd'] != $formdata['pwd2']) {
//Checking for matching password values
$err = 1;
$errpwd = "Passwords do not match";
$errpwd2 = "Passwords do not match";
} else {
$sql = "INSERT INTO users (fname, lname, email, pwd, phone, dateCreated, admin) VALUES (:fname, :lname, :email, :pwd, :phone, :dateCreated, :admin)";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(":fname", $formdata['fname']);
$stmt->bindValue(":lname", $formdata['lname']);
$stmt->bindValue(":email", $formdata['email']);
$stmt->bindValue(":pwd", $formdata['pwd']);
$stmt->bindValue(":phone", $formdata['phone']);
$stmt->bindValue(":dateCreated", $rightnow);
$stmt->bindValue(":admin", 0);
if ($stmt->execute()) {
$showform = 0;
echo "<p class='error'> Recorded!</p>";
} else {
echo "<p class='error'> Sorry, there was an error!</p>";
}
}
?>

Check mysqli Insert Query excuted ok and display message and send email

I am creating a registration form for a project, nothing secure or advanced, i am still fairly new to php etc.
I insert the data needed to into a login table and a customer tbl, the data inserts fine. But i cant get the code to check that its worked and fire off a an email and display a message to the user.
I have tried using a value retrieved from the database which would only be there is the user registered successfuly.
if($userID != null)
{
$msg1 = "Thank You! you are now registered, please check your email for a verification link to verify your new account! ";
$col1 = "green";
//require_once "Mail.php";
require_once "inc/email.php";
}
I have also tried this
if($query)
{
$msg1 = "Thank You! you are now registered, please check your email for a verification link to verify your new account! ";
$col1 = "green";
//require_once "Mail.php";
require_once "inc/email.php";
}
Thanks,
Edit - Here is all the code,
<?php
include ("inc/mysql.php");
error_reporting(0);
$msg = "";
$col = 'green';
function test_input($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
// define variables and set to empty values
$name = $email = $chkemail = $password = $chkpassword =$address = $towncity = $postcode = "";
//Required field validation
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$msg = "Name is required";
$col = 'red';
} else {
$name = test_input($_POST["name"]);
}
if (empty($_POST["email"])) {
$msg = "Email is required";
$col = 'red';
} else {
$email = test_input($_POST["email"]);
}
if (empty($_POST["chkemail"])) {
$msg = "Please confirm your email address";
$col = 'red';
} else {
$chkemail = test_input($_POST["chkemail"]);
}
if (empty($_POST["password"])){
$msg = "Please enter a password";
$col = 'red';
}
if (empty($_POST["chkpassword"])){
$msg = "Please confirm your password ";
$col = 'red';
} else{
$chkpassword = test_input($_POST["chkpassword"]);
if(($_POST["password"]) != $chkpassword) {
$msg = "Please check your password is correct";
$col = 'red';
} else{
$password = test_input($_POST["password"]);
}
}
if (empty($_POST["address"])) {
$msg = "Please enter the first line of your address";
$col = 'red';
} else {
$address = test_input($_POST["address"]);
}
if (empty($_POST["towncity"])) {
$msg = "Please enter the first line of your Town or City";
$col = 'red';
} else {
$towncity= test_input($_POST["towncity"]);
}
if (empty($_POST["postcode"])) {
$msg = "Please enter your postcode";
$col = 'red';
} else {
$postcode = test_input($_POST["postcode"]);
$customerVeri = "N";
if($customerVeri == "N"){
$name = mysqli_real_escape_string($db, $name);
$email = mysqli_real_escape_string($db, $email);
$password = mysqli_real_escape_string($db, $password);
$password = md5($password.substr($email,0,3));
$chkpassword = md5($password.substr($email,0,3));
$verifyLink = md5(substr($name,0,3).substr($email,0,3));
$sql="SELECT customerEmail FROM customer_tbl WHERE customerEmail='$email'";
$result=mysqli_query($db,$sql);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
if(mysqli_num_rows($result) == 1)
{
$msg1 = "Sorry...This email already exists, please enter another or login...";
$col1 = "red";
}
else
{
$query = mysqli_query($db, "INSERT INTO login_tbl (customerEmail, customerPassword)VALUES ('$email', '$password')");
$sql="SELECT userID FROM login_tbl WHERE customerEmail='$email'";
$result=mysqli_query($db,$sql);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
$userID = $row['userID'];
$query2 = mysqli_query($db, "INSERT INTO customer_tbl (customerName, userID, customerEmail, customerPassword, customerAddress, customerTowncity, customerPostcode, customerVerified, customerVerifiedlink)VALUES ('$name', '$userID', '$email', '$password','$address','$towncity','$postcode','$customerVeri','$verifyLink')");
echo("Error description: " . mysqli_error($db));
}
}
}
}
if($userID != null)
{
$msg1 = "Thank You! you are now registered, please check your email for a verification link to verify your new account! ";
$col1 = "green";
//require_once "Mail.php";
require_once "inc/email.php";
}
echo '<div style="color:'.$col.'">';
echo $msg;
echo '</div>';
echo '<div style="color:'.$col1.'">';
echo $msg1;
echo '</div>';
?>
Seems there was no issue, but instead an issue with the email.php that stopped the rest of the statement being executed. Now to pick that to bits. Sometimes a few hours away from the screen is all it needs!
Thanks all that answered..
You shouldn't check every statement for the success
The modern programming doesn't work this way. Any statement can report an error in case one occurs. While if there was no error, then everything went all right.
So, just get rid of all conditions and send your email.

Trouble inserting PHP variables into Mysqli

I am trying to insert data from a form I have made into my MYsql table using mysqli but whenever I submit my form it just displays the successfully connected to db server. Any ideas? It should show my errors for the insert shouldn't it?
<?php
if ($_POST['submit']) {
$errormsg = "";
$name = $_POST['name'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$connection = #mysqli_connect("$hostname","$username", "$password", "$database");
if(!$connection){
die("<p>The database server is not available.</p>".mysqli_error());
}
echo "<p>Sucessfully connected to the database server.</p>";
if((!$name)||(!$password)||(!$password2)||(!$email)||(!$phone)){ /* Checks if all inputs are filled*/
$errormsg = "Please insert the required fields below<br />";
if ($name == "")
{
$errormsg = $errormsg . "Enter a name.<br />";
}
if ($password == "")
{
$errormsg = $errormsg . "Please enter a password.<br />";
}
if ($password2 =="")
{
$errormsg = $errormsg . "Please re-enter your password.<br />";
}
if ($email =="")
{
$errormsg = $errormsg . "Please enter an email address.<br />";
}
if ($phone =="")
{
$errormsg = $errormsg . "Please enter a phone number.<br />";
}
if($errormsg){
echo "$errormsg";
}
}
if($password != $password2) {
$errormsg = $errormsg. "Your passwords must match!<br/>";
}
function checkEmail($email){ //begin email check function
$sql = "SELECT count(email) FROM CUSTOMER WHERE email='$email'";
$result = mysqli_result(mysqli_query($sql),0);
if( $result > 0 ){
$errormsg = $errormsg. "There is already a user with that email!";
}//end email check function
if(!$errormsg)
{
$insertquery = "INSERT INTO CUSTOMER (customer_no, name, password, email, phone)
VALUES(NULL, '$name', '$password', '$email', '$phone')";
$queryresult = mysqli_query($insertquery);
if($queryresult)
{
echo("<br>Registration sucessful");
}
else
{
echo("<br>registration was not sucessful");
}
}
}
}
?>
May be this can work. You can try this:
<?php
if ($_POST['submit']) {
$errormsg = "";
$name = isset($_POST['name'])?$_POST['name']:NULL;
$password = isset($_POST['password'])?$_POST['password']:NULL;
$password2 = isset($_POST['password2'])?$_POST['password2']:NULL;
$email = isset($_POST['email'])?$_POST['email']:NULL;
$phone = isset($_POST['phone'])?$_POST['phone']:NULL;
//Try by removing #, since it ignores any error that may occur here while connecting to mysql
$connection = mysqli_connect("$hostname","$username", "$password", "$database");
if(!$connection)
die("<p>The database server is not available.</p>".mysqli_error());
echo "<p>Sucessfully connected to the database server.</p>";
if(empty($name)||empty($password)||empty($password2)||empty($email)||empty($phone))
{ // Checks if all inputs are filled
$errormsg = "Please insert the required fields below<br />";
if ($name == "")
$errormsg = $errormsg . "Enter a name.<br />";
if ($password == "")
$errormsg = $errormsg . "Please enter a password.<br />";
if ($password2 =="")
$errormsg = $errormsg . "Please re-enter your password.<br />";
if ($email =="")
$errormsg = $errormsg . "Please enter an email address.<br />";
if ($phone =="")
$errormsg = $errormsg . "Please enter a phone number.<br />";
if($errormsg)
echo "$errormsg";
}
if($password != $password2)
$errormsg = $errormsg. "Your passwords must match!<br/>";
function checkEmail($email)
{ //begin email check function
$sql = "SELECT count(email) FROM CUSTOMER WHERE email='$email'";
$result = mysql_result(mysqli_query($connection,$sql),0);//see the difference
if( $result > 0 )
$errormsg = $errormsg. "There is already a user with that email!";
}//end email check function
if(!$errormsg)
{
$insertquery = "INSERT INTO CUSTOMER (customer_no, name, password, email, phone)
VALUES(NULL, '$name', '$password', '$email', '$phone')";
$queryresult = mysqli_query($connection,$insertquery);//see the difference
if($queryresult)
echo("<br>Registration sucessful");
else
echo("<br>registration was not sucessful");
}
}
}
?>
You can learn more from here. Enjoy!

PHP form not posting to database

it validates and displays the errors in my arrays properly, however it doesn't POST to my database. All the naming of fields is correct on the form (case correct too), PHP, and MYSQL, dbconnect.php are all correct and proper. The problem i believe is somewhere in the array function. Now I just started learning PHP this month so please go easy on me. Thanks for the help!
<?php
include ('scripts/dbconnect.php');
$Name = mysql_real_escape_string($Name);
$Email = mysql_real_escape_string($Email);
if (isset($_POST['formsubmitted'])) {
$error = array();//Declare An Array to store any error message
if (empty($_POST['Name'])) {//if no name has been supplied
$error[] = 'Please Enter Your Name ';//add to array "error"
} else {
$Name = $_POST['Name'];//else assign it a variable
}
if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*#([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['Email'])) { //regular expression for email validation
$Email = $_POST['Email'];
} else {
$error[] = 'Your EMail Address is Invalid ';
}
}
if (empty($error)) //Send to database if no errors
mysql_query("INSERT INTO InviteRequestDB ( 'Name', 'Email' ) VALUES ( '$Name', '$Email' )");
mysql_close($connect); //Close connection to database
foreach ($error as $key => $values) {
echo "<li style=color:#FFF> $values </li>";
}
?>
Now I know I shouldn't be using mysql. But I ran into too many problems with mysqli and this is just a simple contact form.
Also should I be doing mysql_real_escape_string on each variable as i am doing now? Or is the order of the procedure not correct?
<form action="applyforinvite.php" method="post">
<input class="textbox" type="text" name="Name" />
<input class="textbox" type="text" name="Email" />
<input type="hidden" name="formsubmitted" value="TRUE" />
<input type="submit" value="Register" />
</form>
Thanks for the help!
You shouldn't quote the column names in the INSERT query. ('name, 'email') should be (name, email).
Also, don't use the php_mysql extension for new applications, it's deprecated. Try MySQLi or PDO.
Final edit( lol ), try this -- fixed the multiple issues with the code:
if (isset($_POST['formsubmitted'])) {
$error = array(); //Declare An Array to store any error message
if (empty($_POST['Name'])) { //if no name has been supplied
$error[] = 'Please Enter Your Name '; //add to array "error"
} else {
$Name = mysql_real_escape_string($_POST['Name']); //else assign it a variable
}
if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*#([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['Email'])) { //regular expression for email validation
$Email = mysql_real_escape_string($_POST['Email']);
} else {
$error[] = 'Your EMail Address is Invalid ';
}
if (empty($error)) //Send to database if no errors
{
mysql_query("INSERT INTO InviteRequestDB (Name, Email) VALUES ( '$Name', '$Email' )");
}
}
mysql_close($connect); //Close connection to database
foreach ($error as $key => $values) {
echo "<li style=color:#FFF> $values </li>";
}
Change
mysql_query("INSERT INTO InviteRequestDB ( 'Name', 'Email' ) VALUES ( '$Name', '$Email' )");
To
mysql_query('INSERT INTO InviteRequestDB ( Name, Email ) VALUES ( "'.$Name.'", "'.$Email.'" )') or die(mysql_error());
EDIT
<?php
include ('scripts/dbconnect.php');
if(isset($_POST['formsubmitted'])){
# Will contain errors
$Error = array();
# Email
$Email = (isset($_POST['Email']) ? $_POST['Email'] : '');
if($Email == '' OR !preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*#([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/', $Email)){
$Error[] = 'Email address is invalid.';
}
# Name
$Name = (isset($_POST['Name']) ? $_POST['Name'] : '');
if($Name == ''){
$Error[] = 'Please enter your name.';
}
if(count($Error)){
echo '<ul>';
foreach($Error as $Value){
echo '<li style="color: #FFF;">'.$Value.'</li>';
}
echo '</ul>';
} else {
// Query
mysql_query('INSERT INTO InviteRequestDB ( Name, Email ) VALUES ( "'.$Name.'", "'.$Email.'" )') or die(mysql_error());
}
//Close connection to database
mysql_close($connect);
}
?>
<?PHP
require_once('scripts/dbconnect.php');
if (!$link) { //Change $link to be your connection variable
die("Not connected : " . mysql_error());
}
if (!$db_selected) { //Change $db_selected to be the variable you set mysql_select_db on
die ("Can't use database : " . mysql_error());
}
if (isset($_POST['formsubmitted'])) {
$error = array();//Declare An Array to store any error message
if (empty($_POST['Name'])) {//if no name has been supplied
$error[] = 'Please Enter Your Name ';//add to array "error"
} else {
$Name = mysql_real_escape_string($_POST['Name']);//else assign it a variable
}
if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*#([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['Email'])) { //regular expression for email validation
$Email = mysql_real_escape_string($_POST['Email']);
} else {
$error[] = 'Your EMail Address is Invalid ';
}
if (count($error) == 0){ //Send to database if no errors
mysql_query("INSERT INTO `InviteRequestDB` (`Name`, `Email`) VALUES('$Name', '$Email')")or die(mysql_error());
} else {
foreach ($error as $key => $values) {
echo "<li style=color:#FFF> $values </li>";
}
}
mysql_close($connect); //Close connection to database
}

Categories