Php Form
PHP Form
index.php
<?php
$submit_flag = false;
if(isset($_POST['name'])){
$submit_flag = true;
$server = "localhost";
$username = "root";
$password ="";
$con = mysqli_connect($server, $username, $password);
if(!$con){
die("connection to database failed". mysqli_connect_error());
}
// echo "Connection Sucessful";
$name = $_POST['name'];
$age = $_POST['age'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$sql = "INSERT INTO `general_data`.`travel` (`name`, `age`, `phone`, `email`, `date`) VALUES ('$name', '$age', '$phone', '$email', current_timestamp());";
// echo $sql;
if($con->query($sql)==true){
// echo "Success";
}
else{
echo "ERROR . $con->error";
}
$con->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css2?family=Sriracha&family=Srisakdi:wght@700&display=swap" rel="stylesheet">
<title>PHP</title>
</head>
<body>
<img class="bg" src="https://source.unsplash.com/1600x800/?travel" alt="randomImage">
<div class="container">
<h1>Travel Form</h1>
<?php
if($submit_flag==true){
echo"<p>Thanks for Submission</p>";
}
?>
<form action="index.php" method="POST">
<input type="text" name="name" id="name" placeholder="Enter your name">
<input type="text" name="age" id="age" placeholder="Age">
<input type="text" name="phone" id="phone" placeholder="Phone No.">
<input type="text" name="email" id="email" placeholder="Email">
<button class="btn">Submit</button>
</form>
</div>
</body>
</html>
$submit_flag = false;
if(isset($_POST['name'])){
$submit_flag = true;
$server = "localhost";
$username = "root";
$password ="";
$con = mysqli_connect($server, $username, $password);
if(!$con){
die("connection to database failed". mysqli_connect_error());
}
// echo "Connection Sucessful";
$name = $_POST['name'];
$age = $_POST['age'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$sql = "INSERT INTO `general_data`.`travel` (`name`, `age`, `phone`, `email`, `date`) VALUES ('$name', '$age', '$phone', '$email', current_timestamp());";
// echo $sql;
if($con->query($sql)==true){
// echo "Success";
}
else{
echo "ERROR . $con->error";
}
$con->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css2?family=Sriracha&family=Srisakdi:wght@700&display=swap" rel="stylesheet">
<title>PHP</title>
</head>
<body>
<img class="bg" src="https://source.unsplash.com/1600x800/?travel" alt="randomImage">
<div class="container">
<h1>Travel Form</h1>
<?php
if($submit_flag==true){
echo"<p>Thanks for Submission</p>";
}
?>
<form action="index.php" method="POST">
<input type="text" name="name" id="name" placeholder="Enter your name">
<input type="text" name="age" id="age" placeholder="Age">
<input type="text" name="phone" id="phone" placeholder="Phone No.">
<input type="text" name="email" id="email" placeholder="Email">
<button class="btn">Submit</button>
</form>
</div>
</body>
</html>
style.css
*{
margin: 0px;
padding: 0px;
font-family: 'Sriracha', cursive;
}
.container{
max-width: 80%;
/* background-color: chartreuse; */
padding: 26px;
margin: auto;
}
.container h1{
font-family: 'Srisakdi', cursive;
text-align: center;
font-size: 50px;
}
input{
width: 80%;
margin: 11px auto;
border: 3px solid;
border-radius: 6px;
font-size: 17px;
padding: 4px;
outline: none;
}
.btn{
color: white;
background-color: blueviolet;
padding: 7px 13px;
margin: 12px;
border-radius: 28px;
cursor: pointer;
}
form{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.bg{
width: 100%;
position: absolute;
z-index: -1;
opacity: 90%;
}
.container p{
color: chartreuse;
text-align: center;
font-size: 20px;
}
margin: 0px;
padding: 0px;
font-family: 'Sriracha', cursive;
}
.container{
max-width: 80%;
/* background-color: chartreuse; */
padding: 26px;
margin: auto;
}
.container h1{
font-family: 'Srisakdi', cursive;
text-align: center;
font-size: 50px;
}
input{
width: 80%;
margin: 11px auto;
border: 3px solid;
border-radius: 6px;
font-size: 17px;
padding: 4px;
outline: none;
}
.btn{
color: white;
background-color: blueviolet;
padding: 7px 13px;
margin: 12px;
border-radius: 28px;
cursor: pointer;
}
form{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.bg{
width: 100%;
position: absolute;
z-index: -1;
opacity: 90%;
}
.container p{
color: chartreuse;
text-align: center;
font-size: 20px;
}



Comments
Post a Comment