<pre><?php
$server="localhost";
$username="root";
$password = "";
$con=mysqli_connect($server, $username, $password);
if(!$con){
die("connection to this database failed due to".mysqli_connect_error());
}
echo "Success connecting to the db";
$name= $_POST['name'];
$age= $_POST['age'];
$gender= $_POST['gender'];
$email= $_POST['email'];
$phone= $_POST['phone'];
$desc= $_POST['desc'];
$sql="INSERT INTO `data1` (`name`, `age`, `gender`, `email`, `phone`, `other`, `dt`) VALUES ( '$name', '$age', '$gender', '$email', '$phone', '$desc', current_timestamp());";
echo $sql;
?>
below is the html code
<pre><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>travel form</title>
<link rel="stylesheet" href="stle.css">
</head>
<body>
<div class="container">
<h1>travel form</h1>
<p>Enter details to confirm participation</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="Enter your age">
<input type="text" name="gender" id="gender" placeholder="Enter your gender">
<input type="email" name="email" id="email" placeholder="Enter your email">
<input type="phone" name="phone" id="phone" placeholder="Enter your phone number">
<textarea name="desc" id="desc" cols="30" rows="10" placeholder="Enter info"></textarea>
<button class="btn">Submit</button>
<button class="btn">Reset</button>
</form>
</div>
<script src="index.js"></script>
</body>
</html>
error is:
Success connecting to the db
Notice: Undefined index: name in /Applications/XAMPP/xamppfiles/htdocs/first/index.php on line 15
Notice: Undefined index: age in /Applications/XAMPP/xamppfiles/htdocs/first/index.php on line 16
Notice: Undefined index: gender in /Applications/XAMPP/xamppfiles/htdocs/first/index.php on line 17
Notice: Undefined index: email in /Applications/XAMPP/xamppfiles/htdocs/first/index.php on line 18
Notice: Undefined index: phone in /Applications/XAMPP/xamppfiles/htdocs/first/index.php on line 19
Notice: Undefined index: desc in /Applications/XAMPP/xamppfiles/htdocs/first/index.php on line 20
INSERT INTO `data1` (`name`, `age`, `gender`, `email`, `phone`, `other`, `dt`) VALUES ( '', '', '', '', '', '', current_timestamp());
What I have tried:
i have tried reading the code again and again but it yields no results.