INSERT INTO语句不能正常工作PHP / MySQLI

时间:2016-09-15 02:36:43

标签: php mysql insert-into

我已经经过这个网站不停地寻找解决我的问题的方法,但空手而归。 这是问题所在,每当我使用以下INSERT INTO语句时,没有任何内容插入到我的数据库中,代码运行顺利,但在一天结束时我的数据库仍为空(不包括我自己手动插入的值)。 我还想指出,我运行了一个SELECT FROM语句,可以很好地从数据库中返回手动插入的值。 无论如何这里是代码:

连接数据库

$link = mysqli_connect("localhost", "root", "", "prototype");

插入代码

  if ($error) echo "There were error(s) in your signup details:".$error;
else
{

  $query = "SELECT * FROM `users` WHERE email = '".mysqli_real_escape_string($link, $_POST['email'])."'";

  $result = mysqli_query($link, $query);

  $results = mysqli_num_rows($result);

  echo $results;

  if ($results) echo " This email address is already taken. Would you like to log in?";
  else
  {
    $query = "INSERT INTO `users`(`email`, `password`) VALUES ('".mysqli_real_escape_string($link, $_POST['email']).', '.md5(md5($_POST['email']).$_POST['password'])."')";

    mysqli_query($link, $query);

    echo "You've been registered!";

    $_SESSION['id'] = mysqli_insert_id($link);

    print_r($_SESSION);

    // Redirect to logged in page

  }

1 个答案:

答案 0 :(得分:1)

尝试更改插入查询,如下所示

$query = "INSERT INTO `users`(`email`, `password`) VALUES ('".mysqli_real_escape_string($link, $_POST['email'])."', '".md5(md5($_POST['email']).$_POST['password'])."')";