My PHP code is not running on XAMPP
i'm using xamppv3.1.0.3.1.0. i stored my php form in the htdocs folder. when i run my script to connect to my database, it doesn't connect but rather displays the php code. can someone pls help me with this?
this is my index.php code and Html code as well and I put the same name whatever I have written in html code and in MySQL database also
but I'm getting this error i don't know why please help!!!!
IN localhost it is showing an error
Notice: Undefined index: name in C:\xampp\htdocs\new\index.php on line 18
Notice: Undefined index: email in C:\xampp\htdocs\new\index.php on line 19
Notice: Undefined index: age in C:\xampp\htdocs\new\index.php on line 20
Notice: Undefined index: gender in C:\xampp\htdocs\new\index.php on line 21
Notice: Undefined index: address in C:\xampp\htdocs\new\index.php on line 22
Notice: Undefined index: phone in C:\xampp\htdocs\new\index.php on line 23
Notice: Undefined index: desc in C:\xampp\htdocs\new\index.php on line 24
<?php
// Set connection variables
$server = "localhost"; $username = "root"; $password = "";
// Create a database connection
$con = mysqli_connect($server, $username, $password);
// Check for connection success
if(!$con){ die("connection to this database failed due to" . mysqli_connect_error()); }
echo"success connecting to the db";
$name = $_POST['name'];
$email = $_POST['email'];
$age = $_POST['age'];
$gender = $_POST['gender'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$desc = $_POST['desc'];
$sql = "INSERT INTO 'jabalpur'.`best` (`name`, `email`, `age`, `gender`, `address`, `phone`, `other`, `dt`) VALUES ('$name', '$email', '$age', '$gender', '$address', '$phone', '$desc', current_timestamp());";
echo $sql;
// Execute the query if($con->query($sql) == true){ echo "Successfully inserted";
// Flag for successful insertion $insert = true;}else{ echo "ERROR: $sql <br> $con->error";}
// Close the database connection$con->close();
?>
here my HTMLcode
<!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>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class= "container">
<h1>Welcome To Jabalpur</h1>
<p>Enter your details here to have the best vacations in jabalpur and to know the mesmerising beauty of the Jabalpur </p>
<p> And to book your comfort place now</p>
</div>
<img class="bg" src="bg1.jpg">
<form action="index.php" method="post" >
<input type="text" name="name" id="name" placeholder="enter your name here"><br>
<input type="email" name="email" id="email" placeholder="enter your email id here"><br>
<input type="text" name="age" id="age" placeholder="enter your age here"><br>
<select><option>male</option><option>female</option><option>third gender</option></select></br
<textarea name=address id= address rows="1"></textarea><br>
<input type="phone" name="phone" id="phone">
<textarea name="desc" id="desc" cols="5" rows="1"placeholder="enter any other information here" ></textarea>
<button class="btn">submit</button> </form>
<script src="index.js">
</script>
</body>
</html>