将变量添加为VALUE时,PHP MySQL INSERT停止工作

时间:2014-01-13 19:31:38

标签: php

<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
if (isset($_POST['submit'])) {

  $passport = substr(str_shuffle("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20);

  $link = mysqli_connect("localhost","php","","A");

  $query = "INSERT INTO users (nickname, passport, mail, password, age, sex, is_registered)
            VALUES ('$_POST[nickname]', '$passport', '$_POST[mail]', md5('$_POST[password]'), '$_POST[age]', '$_POST[sex]', '1')";

  $result = $link->query($query);

}
?>

passport删除$passport$query会让它再次发挥作用吗?

echo "$passport";也有效。没有报告错误。

1 个答案:

答案 0 :(得分:0)

试试这个,

 md5($_POST['password'])

而不是

md5('$_POST[password]')

CODE:

    $query = "INSERT INTO users (nickname, passport, mail, password, age, sex, is_registered)
    VALUES ('$_POST[nickname]', '$passport', '$_POST[mail]', '".md5($_POST['password'])."', '$_POST[age]', '$_POST[sex]', '1')";