php通知未定义记录

时间:2017-08-16 08:05:54

标签: php html

当我在我的html中插入新记录时,我会收到错误。还是只是我的代码错了?是插入新记录的代码?

   <?php

    $servername = "localhost";
    $dbusername = "root";
    $dbpassword = "";
    $dbname = "signupform";

    $StudentID =$_POST['StudentID'];
    $Password = $_POST['Password'];
    $Cpassword = $_POST['Cpassword'];
    $Fname = $_POST['Fname'];
    $Lname = $_POST['Lname'];
    $Gender = $_GET['Gender'];
    $Email = $_POST['Email'];
    $Phone = $_POST['Phone'];

    $conn = mysqli_connect($servername, $dbusername, $dbpassword, $dbname)or die ("Cannot connect");


    $sql= "INSERT INTO studentdatabase (StudentID,Password,First_Name,Last_Name,Gender,Email,Phone)
            VALUE('.$StudentID.','.$Password.','.$Fname.','.$Lname.','.$Gender.','.$Gender.','.$Phone.')";

            if(!mysqli_query($conn, $sql))
            {
                die("error inserting record");

            }

        ?>

这是错误总是显示我仍然初学者这个PHP和HTML我希望人们可以帮助我。我真的不明白我的错在哪里

( ! ) Notice: Undefined index: StudentID in D:\wamp\www\HAHA\saynup.php on line 8
Call Stack
#   Time    Memory  Function    Location
1   0.0010  135248  {main}( )   ...\saynup.php:0

( ! ) Notice: Undefined index: Password in D:\wamp\www\HAHA\saynup.php on line 9
Call Stack
#   Time    Memory  Function    Location
1   0.0010  135248  {main}( )   ...\saynup.php:0

( ! ) Notice: Undefined index: Cpassword in D:\wamp\www\HAHA\saynup.php on line 10
Call Stack
#   Time    Memory  Function    Location
1   0.0010  135248  {main}( )   ...\saynup.php:0

( ! ) Notice: Undefined index: Fname in D:\wamp\www\HAHA\saynup.php on line 11
Call Stack
#   Time    Memory  Function    Location
1   0.0010  135248  {main}( )   ...\saynup.php:0

( ! ) Notice: Undefined index: Lname in D:\wamp\www\HAHA\saynup.php on line 12
Call Stack
#   Time    Memory  Function    Location
1   0.0010  135248  {main}( )   ...\saynup.php:0

( ! ) Notice: Undefined index: Email in D:\wamp\www\HAHA\saynup.php on line 14
Call Stack
#   Time    Memory  Function    Location
1   0.0010  135248  {main}( )   ...\saynup.php:0

( ! ) Notice: Undefined index: Phone in D:\wamp\www\HAHA\saynup.php on line 15
Call Stack
#   Time    Memory  Function    Location
1   0.0010  135248  {main}( )   ...\saynup.php:0

2 个答案:

答案 0 :(得分:0)

您需要在html表单上指定POST方法:

HTTP Status 404 - /com.example.child/WEB-INF/view/app/example.jsp

如果没有你通过GET提交的额外属性(即你可以看到这些值出现在你的URL的查询字符串部分中),那么它们最终会出现在PHP的/com.example.common/WEB-INF/view/app/example.jsp数组而不是overlay

有关详情,请参阅此处:http://php.net/manual/en/language.variables.external.php

答案 1 :(得分:0)

 $servername = "localhost";
    $dbusername = "root";
    $dbpassword = "";
    $dbname = "signupform";

    if (!empty( $_POST['StudentID'])) {
      $StudentID =$_POST['StudentID'];
    }
    if (!empty( $_POST['Password'])) {
      $Password = $_POST['Password'];
    }

$conn = mysqli_connect($servername, $dbusername, $dbpassword, $dbname)or die ("Cannot connect");


    $sql= "INSERT INTO studentdatabase (StudentID,Password,First_Name,Last_Name,Gender,Email,Phone)
            VALUE('.$StudentID.','.$Password.','.$Fname.','.$Lname.','.$Gender.','.$Gender.','.$Phone.')";

            if(!mysqli_query($conn, $sql))
            {
                die("error inserting record");

            }

同时检查$Cpassword, $Fname, $Lname, $Gender, $Email, $Phone

的条件

检查empty()方法....如果你在提交时获得值空白,那么它会给你通知....