This file is the action file .When user submits wrong values , it heads back to the file named vform.php and asks user the correct input. But for me , after entering correct values and clicking on register , neither values are entering into wamp db, nor showing successful message. below is the code for adding values into db. after successful validation , it heads toregsuccess.php where it shows registration successful message. I don't know what exactly is the reason why values are not entering into db .
<?php
ob_start();
session_start();
include("DBConnection.php"); // include the connection object from the
DBConnection.php
if ($_POST['submit'])
{
$inFullname = trim($_POST["name"]);
$inEmail = trim($_POST["email"]);
$inPhone = trim($_POST["phonenumber"]);
$_SESSION['valid_name']=$inFullname;
$_SESSION['valid_email']=$inEmail;
$_SESSION['valid_phone']=$inPhone;
if( !preg_match("/^([a-zA-Z' ]+)$/",$inFullname) ||!preg_match('',$inEmail) || !preg_match('',$inPhone) ){
if(preg_match("/^[a-zA-Z-,]+(\s{0,1}[a-zA-Z-, ])*$/",$inFullname)){
$_SESSION['valid_name']=$inFullname;
}else {
$_SESSION['name_error'] = "enter valid name";
}
if(preg_match("/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-
Za-z]{2,4})$/",$inEmail)){
$_SESSION['valid_email']=$inEmail;
} else{
$_SESSION['mail_error'] = "enter valid mail";
}
if(preg_match("/^\d{3}-\d{3}-\d{4}$/",$inPhone)){
$_SESSION['valid_phone']=$inPhone;
} else{
$_SESSION['phone_error'] = "enter valid phone number";
}
header('Location: vform.php');
die();
}
$stmt = $db->prepare("INSERT INTO DETAILS(NAME,EMAIL,PHONENUMBER) VALUES(?,?,?)"); //Fetching all the records with input credentials
$stmt->bind_param("sss", $inFullname,$inEmail,$inPhone); //Where s indicates string type. You can use i-integer, d-double
$stmt->execute();
$result = $stmt->affected_rows;
$stmt -> close();
$db -> close();
if($result > 0) {header("location: RegSuccess.php");} // user will be taken to the success page
else{ echo 'Oops. Something went wrong. Please try again <a href="vform.php">Try Login</a>';}
}
?>