无法将表单数据插入MySQL

时间:2016-12-29 20:19:35

标签: php mysql

    $name = mysqli_real_escape_string($connection, $_POST['name']);
    $surname = mysqli_real_escape_string($connection, $_POST['surname']);
    $username = mysqli_real_escape_string($connection, $_POST['username']);
    $email = mysqli_real_escape_string($connection, $_POST['email']);
    $pw1 = mysqli_real_escape_string($connection, $_POST['pw1']); //use this one
    $pw2 = mysqli_real_escape_string($connection, $_POST['pw2']);


    $query = "INSERT INTO users ('name', 'surname', 'username', 'email', 'password') VALUES ($name, $surname, $username, $email, $pw1)";
    $result = mysqli_query($connection, $query); 
    mysqli_free_result($result);
    mysqli_close($connection);

当我输入表格数据时,我会收到警告

"警告:mysqli_free_result()期望参数1为mysqli_result,布尔值在......"并且没有数据发送到数据库。

我用:

连接到数据库
<?php
$connection = mysqli_connect('localhost', 'root', 'password', 'sports_world');

if(!$connection){
    die("connection failed");
}

?>

如果我不使用mysqli_free_result($ result)和mysqli_close($ connection)方法,我不会收到任何警告,但是,数据仍然没有发送到数据库。

0 个答案:

没有答案