【问题标题】:I can't send data from input fields to my MySQL database我无法将输入字段中的数据发送到我的 MySQL 数据库
【发布时间】:2017-11-21 20:15:39
【问题描述】:

我有一个小问题。我有一个注册表。它工作得几乎完美,我可以检查输入字段的值,我可以检查天气我们在数据库中是否有相同的用户名,但如果一切正常,我无法将数据发送到我的数据库。我使用它作为管理员/根,所以我有特权。问题是什么?请帮忙!

<?php    
  // declaring variables from input fields
  $email = $_POST['email'];
  $username=$_POST['username'];
  $password=$_POST['password'];
  $password2=$_POST['password2'];


  function registration ($username, $email, $password) {
      //new user registering
      //return true or errormessage

      //connecting to database, YEAH IT WORKS!
      $connection = connecting_to_db();

      //checking unique of username and IT WORKS!
      $result = $connection->query("SELECT * FROM user WHERE username='".$username."'");

      if (!$result) {
        throw new Exception ('We couldnt query. Sorry.');
      }
      if ($result->num_rows>0) {
        throw new Exception ('We have already this username! Choose something else!');
      }
      // if it is OK send it to the DB AND THIS IS NOT WORKING :-(
      $result = $connection->query("INSERT INTO user VALUES'".$username."', shal('".$password."'), '".$email."')");

      // I get alwasy this way and get this message.
      if (!$result) {
        throw new Exception ('We couldnt save your datas in our database. Try it later!');
      }
      return true;
  }

?>

【问题讨论】:

标签: php mysql registration user-registration


【解决方案1】:

您的插入查询中似乎有 shal(letter L) 而不是 sha1(# one)。从查询中打印出您的结果,您应该会看到您的问题。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2021-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-20
  • 2020-07-22
  • 1970-01-01
相关资源
最近更新 更多