<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {font-family: Arial, Helvetica, sans-serif;}
* {box-sizing: border-box;}


input[type=text], select, textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background-color: #f2f2f2;
  box-sizing: border-box;
  margin-top: 4px;
  margin-bottom: 5px;
  resize: vertical;
}

input[type=submit] {
  background-color: #73AD21;
  color: white;
  padding: 12px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

input[type=submit]:hover {
  background-color: #45a049;
}

.container {
  background-color:white;
  padding: 15px;
}
</style>
</head>
<body>
<br>
<div class="container">
  <div>
  <form  method="post" name="alertform">
    <label for="fname">Full Name:</label>
    <input type="text" id="fname" name="fname" placeholder="John Doe">

    <label for="lname">Phone No:</label>
<input type="text" name="phone" id="name" onFocus="this.value = '';" onBlur="if (this.value == '') 
{this.value = '07*******';}" required pattern="[0-9]{10,12}"
  placeholder="eg.0700000000"/>

       <label for="subject">Subject</label>
    <textarea id="subject" name="subject" placeholder="Write something.." style="height:50px"></textarea>
    <div style="text-align: center;">
    <input type="submit"  name="submit" value="Submit" onclick="window.alert('Hello'+' '+ document.alertform.fname.value+' '+'We are glad to here from you');">
  </div>
  </form>
</div>
<hr width="90%" color="#ccc">
<?php
if(isset($_POST["submit"])){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "masomo";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO messages(Name, Phone,Subject)
VALUES ('".$_POST["fname"]."','".$_POST["phone"]."','".$_POST["subject"]."')";

if ($conn->query($sql) === TRUE) {
echo "<script type= 'text/javascript'>alert('Sent successfully ');</script>";
echo "<script type='text/javascript'>location.href = 'index.php';</script>";
} else {
echo "<script type= 'text/javascript'>alert('Error: " . $sql . "<br>" . $conn->error."');</script>";
}

$conn->close();
}
?>
</div></br>
</body>
</html>
