注意:未定义的变量:第16行的C:\ xampp \ htdocs \ port \ w6 \ insertRecord.php中的firstname

时间:2017-11-27 07:22:51

标签: php

问题在于insertRecord.php,但我无法找到它。我也附上了错误的图像

问题在于insertRecord.php,但我无法找到它。我也附上了错误的图像

未定义的变量:名字,姓氏,密码,电子邮件,年龄,性别是问题enter image description here

insertRecord.php

<?php
    include 'connection.php';
    if(isset($_POST['submit']))
    {
        echo"sucee";
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $email = $_POST['email'];
    $password = $_POST['password'];
    $gender = $_POST['gender'];
    $age = $_POST['age'];
    }

    $sql = "INSERT INTO user (FirstName,LastName,Email,Password,Gender,Age) VALUES ('$firstname', '$lastname', '$email', '$password', '$gender', '$age')";


    $result=mysqli_query($connection, $sql);
    include 'watWK6.php';
    include 'selectRecord.php';


    ?>

连接

<?php 
$hostname = 'localhost'; 
$username = 'root'; 
$password = ''; 
$databaseName = 'c7181378'; 
$connection = mysqli_connect($hostname, $username, $password, $databaseName) or exit("Unable to connect to database!");
?>

watWK6.php

<!DOCTYPE html>
<html lang="en">
   <head>
      <title>Web Applications and Technologies</title>
      <link type="text/css" rel="stylesheet" href="main.css" />
   </head>
   <body>
      <header>
         <h1> C7181378</h1> 
      </header>

      <section id="container">
         <form method = "POST" action = "insertRecord.php">
            <fieldset>
                <legend> Enter Customer Details </legend>
                <label> First Name: </label>
                <input type = "text" name = "firstname"/>
                <br/>
                <label> Surname: </label>
                <input type = "text" name = "lastname"/>
                <br/>
                <label> Email: </label>
                <input type = "text" name = "email"/>
                <br/>
                <label> Password: </label>
                <input type = "password" name = "password"/>
                <br/>
                <label> Gender: </label>
                <select name = "gender">
                    <option value = "M"> Male </option>
                    <option value = "F"> Female </option>
                </select>
                <br/>
                <label> Age: </label>
                <input type = "text" name = "age"/>
                <br/>
                <input type = "submit" value = "submit" name = "submit"/>
            </fieldset>
         </form>
      </section>
      <footer>   
         <small> <a href="../index.html">Home</a></small>
      </footer>
   </body>
</html>

<?php
    include 'selectRecord.php';
?>

1 个答案:

答案 0 :(得分:0)

请在insertRecord.php中进行更改 注意:不要使用已弃用和不安全的mysql * -functions,正如Milan Chheda在评论中所说

<?php
    include 'connection.php';
    if(isset($_POST['submit']))
    {
        echo"sucee";
        $firstname = $_POST['firstname'];
        $lastname = $_POST['lastname'];
        $email = $_POST['email'];
        $password = $_POST['password'];
        $gender = $_POST['gender'];
        $age = $_POST['age'];
        $sql = "INSERT INTO user (FirstName,LastName,Email,Password,Gender,Age) VALUES ('$firstname', '$lastname', '$email', '$password', '$gender', '$age')";

        $result=mysqli_query($connection, $sql);

    }

    include 'watWK6.php';
    include 'selectRecord.php';


    ?>