My PHP code is not running on XAMPP

Avatar
  • updated
  • Answered
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?
Duplicates 2
ERROR: INSERT INTO 'jabalpur'.`best` (`name`, `email`, `age`, `gender`, `address`, `phone`, `other`, `dt`) VALUES ('', '', '', '', '', '', '', current_timestamp());

 

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>

im using php/html and phpmyadmin for database in xampp.

<...>

what i want is that when i click the "Accept" it should place a text on Status(column) Accept but what happens is it randomly input a 000-00-00 number in my Date (column).

Avatar
anonymous

Hello and thanks for contacting us. I recommend checking your server logs and code validators for PHP and MySQL.

Avatar
Scott
Hello timecraft,

Thank you for your question on php in xampp. Unfortunately we do not provide custom code solutions. If you are receiving an error message and have a question about that, we can certainly assist with that.

Kindest Regards,
Scott M

Avatar
JeffMa

While I am not very familiar with XAMPP, it does sound like your code is not appropriately being handled by Apache as PHP. You would need to ensure that PHP is properly running on your system. Be sure that all PHP also files also have a .php extension on them. You may test your PHP configuration by creating a phpinfo page that will allow you to see your PHP settings as well.