Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
PHP
<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";

    //making the vairables
    $name= $_POST['name'];
    $age= $_POST['age'];
    $gender= $_POST['gender'];
    $email= $_POST['email'];
    $phone= $_POST['phone'];
    $desc= $_POST['desc'];

    //now we want to insert using post query
    //so we will make a sq; query
    $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

HTML
<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.
Posted
Comments
Richard MacCutchan 2-Apr-22 12:23pm    
It looks like your HTML and PHP code are not connected to each other.
Richard Deeming 4-Apr-22 5:29am    
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation/interpolation to build a SQL query. ALWAYS use a parameterized query.

PHP: SQL Injection - Manual[^]
PHP: Prepared statements and stored procedures - Manual[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900