未定义的索引+未选择数据库

时间:2015-04-12 23:12:24

标签: php mysql database phpmyadmin

我试过这个PHP代码,出现了很多错误,我无法识别 我是初学者的错误在哪里,我真的希望你尽快得到你的帮助

错误:

  

成功连接

     

注意:未定义索引:C:\ xampp \ htdocs \ phpfile.php中的名称在线   23

     

注意:未定义索引:电子邮件在C:\ xampp \ htdocs \ phpfile.php上线   24

     

注意:未定义的索引:手机在C:\ xampp \ htdocs \ phpfile.php上线   25

     

注意:未定义索引:C:\ xampp \ htdocs \ phpfile.php中的密码   第26行错误:INSERT INTO   用户(姓名,电子邮件,电话,密码)VALUES('','','','')没有数据库   选择

HTML表格:

<html>
<head>
<title> event reg </title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<form enctype="from-data" action="phpfile.php" method="post">
          <label for ="name"> User Name :</label>
          <input type="text" name="name" id="name" maxlength="30" Size="30"/>
          <br />
            <br />
          <label for ="email"> E-mail &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;: </label> 
          <input type="email" name="email" id="email" maxlength="255" Size="30"/>
          <br />
            <br />
           <label for ="phone"> Phone &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; :</label>
          <input type="text" name="phone" id="phone" maxlength="10" Size="30"/>
          <br />
            <br />
          <label for ="password"> password &nbsp; &nbsp;: </label> 
          <input type="password" name="password" id="password" maxlength="12" Size="30"/>
          <br />
          <br />

          <label for ="event"> Event name:&nbsp;&nbsp; </label>
          <select name="event" id="event">
          <option value="Inceptionopening"> Inception </option>
          </select>
          <br />
          <br />
           <br />
           <br />

           <input type="submit" name="submit" id="submit" value="submit" />
             <input type="reset" name="reset" id="reset" value="Cnacel" />
</form>
</body>
</html>

//连接到它的PHP代码:

<?php
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "userdb";

    // Create connection
    $conn = mysqli_connect($servername, $dbname);

    // Check connection
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }

    echo "Connected Successfully <br>";

    $name=$_POST['name'];
    $email=$_POST['email'];
    $phone=$_POST['phone'];
    $password=$_POST['password'];
    $sql="INSERT INTO user(name,email,phone,password)VALUES('$name','$email','$phone','$password')";

    if (mysqli_query($conn, $sql)) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }

    mysqli_close($conn);

    ?>

1 个答案:

答案 0 :(得分:0)

试试这个

<?php
        $servername = "localhost";
        $username = "root";
        $password = "";
        $dbname = "userdb";

    $con = mysqli_connect($servername,$username,$password,$dbname);