Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Through proceduraI method want to echo $sql its displaying but some errors are also displaying

<?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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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, email, 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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading