Warning: mysqli::__construct() expects parameter 5 to be integer, string given in C:\xampp\htdocs\project\contactdemo.php on line 35
Warning: mysqli::query(): Couldn't fetch mysqli in C:\xampp\htdocs\project\contactdemo.php on line 44
Warning: main(): Couldn't fetch mysqli in C:\xampp\htdocs\project\contactdemo.php on line 50
Error:INSERT INTO contactphpdem(username,email,mobile,subject) values('Rahul','ragavi@gmail.com','8105189061','nvjmlik')
Warning: mysqli::close(): Couldn't fetch mysqli in C:\xampp\htdocs\project\contactdemo.php on line 52
What I have tried:
<?php
$username= filter_input(INPUT_POST,'username');
$email= filter_input(INPUT_POST,'email');
$mobile= filter_input(INPUT_POST,'mobile');
$subject= filter_input(INPUT_POST,'subject');
if(!empty($username))
{
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$username)) {
echo "Only letters and white space allowed";
}
if(!empty($email))
{
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Invalid email format";
}
if(!empty($mobile))
{
if (!preg_match("/^[0-9]{10}$/",$mobile)) {
echo "Invalid mobile number";
}
if(!empty($subject))
{
if (preg_match("/^[0-9]{10}$/",$subject)) {
echo "Invalid data";
}
$host="localhost";
$dbusername="root";
$dbemail="email";
$dbmobile="mobile";
$dbsubject="subject";
$dbname="contactphpdem";
//Create connection
$conn = new mysqli($host,$dbusername,$dbemail,$dbmobile,$dbsubject,$dbname);
if(mysqli_connect_error()){
die('Connect Error('. mysqli_connect_errno().') '
. mysqli_connect_error());
}
else{
$sql = "INSERT INTO contactphpdem(username,email,mobile,subject)
values('$username','$email','$mobile','$subject')";
if($conn->query($sql))
{
echo"alert('Your are Successfully entered')";
echo"window.open('Home.html','_self')";
}
else{
echo"Error:". $sql ."
". $conn->error;
}
$conn->close();
}
}
else
{
echo"Please share your thoughts or query for us to improve our service";
die();
}
}
else{
echo"Please enter your mobile number";
die();
}
}
else{
echo"Please enter your email id";
die();
}
}
else{
echo"Name should not be empty";
die();
}
?>