-1

I am trying to insert data from my form but i keep getting the "Notice: Undefined index: name in C:\xampp\htdocs\project\insert.php on line 6" error. Any idea how to fix it?

code :

<?php

    require_once("db.php");
    if(isset($_POST["submit"]))

    $name = $_POST["name"];
    $course = $_POST["course"];
    $email = $_POST["email"];
    $phone = $_POST["phone"];
    $date = $_POST["date"];

    $sql = "INSERT INTO registertb(name, course, email, phone, date) VALUES ('" . $name . "','" . $course . "','" . $email . "','" . $phone . "','" . $date . "')";

    $result = mysql_query($sql,$dbconn);

    if($result)
    {
     ?>
    <script type="text/javascript">
    alert('Registration success! ');
    //window.location.href='view.php';
    </script>
    <?php
     }
    else
    {
    ?>
    <script type="text/javascript">
     alert('An error occured while inserting your data');
    </script>
    <?php
    }
    ?>

1 Answers1

0

your $_POST array doesn't have name key, may your from doesn't use post but use get method. try to remove this line: $name = $_POST["name"]; if you have the error:

Notice: Undefined index: course in C:\xampp\htdocs\project\insert.php on line 6

so you can check the

Gouda Elalfy
  • 6,888
  • 1
  • 26
  • 38