<?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 "Sucessfully connecting to db";
// Collect post variables
$name = $_POST['name'];
$age= $_POST['age'];
$gender = $_POST['gender'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$desc = $_POST['desc'];
$sql = " INSERT INTO `trip`.`trip` ( `name`, `age`, `gender`, `email`, `phone`, `others`, `dt`) VALUES ( '$name','$age', '$gender', '$email', '$phone','$desc', current_timestamp());";
echo $sql;
?>
But Its showing
Warning: Undefined array key "name" in C:\xampp\htdocs\ssm\index.php on line 18
Warning: Undefined array key "age" in C:\xampp\htdocs\ssm\index.php on line 19
Warning: Undefined array key "gender" in C:\xampp\htdocs\ssm\index.php on line 20
Warning: Undefined array key "email" in C:\xampp\htdocs\ssm\index.php on line 21
Warning: Undefined array key "phone" in C:\xampp\htdocs\ssm\index.php on line 22
Warning: Undefined array key "desc" in C:\xampp\htdocs\ssm\index.php on line 23
INSERT INTO
trip.trip(name,age,gender,phone,others,dt) VALUES ( ”,”, ”, ”, ”,”, current_timestamp());
>Solution :
First time your are running this page , there are no post varibales sent to the page , so you get this warnings!
and the other thing to mention is , your code is not executing the SQL command you created , so there is no output for that.