Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我做错了什么?Php、mysql插入或查询不起作用_Php_Mysql - Fatal编程技术网

我做错了什么?Php、mysql插入或查询不起作用

我做错了什么?Php、mysql插入或查询不起作用,php,mysql,Php,Mysql,我的注册脚本有问题。无论我输入数据并将其发送到服务器,它都只会显示一条出错的消息,即使表是空的 代码: 若要在数据库中插入字符串,必须添加并重试此操作 为什么要加密数据库中的用户名和电话号码?if中的说明返回true或false?可能是因为这个原因,脚本没有进入查询。我不明白你为什么要散列所有的信息,你用MD%或者类似的东西作为密码是有意义的。当您这样做时,您将如何显示或知道真正的用户名?change echo出错;=>echo mysqli_错误$connect;并检查错误!mysqli_qu

我的注册脚本有问题。无论我输入数据并将其发送到服务器,它都只会显示一条出错的消息,即使表是空的

代码:


若要在数据库中插入字符串,必须添加并重试此操作


为什么要加密数据库中的用户名和电话号码?if中的说明返回true或false?可能是因为这个原因,脚本没有进入查询。我不明白你为什么要散列所有的信息,你用MD%或者类似的东西作为密码是有意义的。当您这样做时,您将如何显示或知道真正的用户名?change echo出错;=>echo mysqli_错误$connect;并检查错误!mysqli_query'YourQuery'{echo mysqli_error;}PHPhil警告:mysqli_num_rows期望参数1是mysqli_结果,第23行的C:\xampp\htdocs\reg_auth.php中给出的布尔值警告:mysqli_num_rows期望参数1是mysqli_结果,第23行的C:\xampp\htdocs\reg_auth.php中给出的布尔值您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解在第1行“\'MD5'borut'\”、\'MD5'pocakaj'\”、\'MD5'041341323'\附近使用的正确语法。我收到以下错误:警告:mysqli_num_rows预期参数1为mysqli_result,第23行C:\xampp\htdocs\reg_auth.php中给出的布尔值警告:mysqli_num_rows期望参数1为mysqli_result,第23行C:\xampp\htdocs\reg_auth.php中给出的布尔值出现问题
<?php

$mysql_host = "localhost";
$mysql_database = "accountsmessengertesttable";
$mysql_user = "root";
$mysql_password = "";

$username = $_GET['username'];
$password = $_GET['password'];
$phone_number = $_GET['phone_num'];

$connect = mysqli_connect($mysql_host,  $mysql_user, $mysql_password, $mysql_database);

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

    $check_for_user = mysqli_query($connect,"SELECT username FROM accounts WHERE username = MD5('$username')"); 
    $check_for_number = mysqli_query($connect,"SELECT phone_number FROM accounts WHERE phone_number = MD5('$phone_number')");


    if(mysqli_num_rows($check_for_user) == 0 && mysqli_num_rows($check_for_number) == 0) {
        $register = mysqli_query($connect, "INSERT INTO accounts (username, password, phone_number) VALUES (MD5('$username'), MD5('$password'), MD5('$phone_number')"); 
    if($register) {
    echo  "registered";
    }
    else { echo "something went wrong"; 
    }
    }

     else if(!mysqli_num_rows($check_for_user) == 0) {
                echo "user_exists";
     } else if(!mysqli_num_rows($check_for_number) == 0) {

     echo "number_exists";

     }




mysqli_close($connect);

?>
<?php

$mysql_host = "localhost";
$mysql_database = "accountsmessengertesttable";
$mysql_user = "root";
$mysql_password = "";

$username = $_GET['username'];
$password = $_GET['password'];
$phone_number = $_GET['phone_num'];

$connect = mysqli_connect($mysql_host,  $mysql_user, $mysql_password, $mysql_database);

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

    $check_for_user = mysqli_query($connect,"SELECT username FROM accounts WHERE username = \'MD5('$username')\'"); 
    $check_for_number = mysqli_query($connect,"SELECT phone_number FROM accounts WHERE phone_number = \'MD5('$phone_number')\'");


    if(mysqli_num_rows($check_for_user) == 0 && mysqli_num_rows($check_for_number) == 0) {
        $register = mysqli_query($connect, "INSERT INTO accounts (username, password, phone_number) VALUES \'(MD5('$username')\', \'MD5('$password')\', \'MD5('$phone_number')\'"); 
    if($register) {
    echo  "registered";
    }
    else { echo "something went wrong"; 
    }
    }

     else if(!mysqli_num_rows($check_for_user) == 0) {
                echo "user_exists";
     } else if(!mysqli_num_rows($check_for_number) == 0) {

     echo "number_exists";

     }




mysqli_close($connect);

?>
<?php

$mysql_host = "localhost";
$mysql_database = "accountsmessengertesttable";
$mysql_user = "root";
$mysql_password = "";

$username = $_GET['username'];
$password = $_GET['password'];
$phone_number = $_GET['phone_num'];

$connect = mysqli_connect($mysql_host,  $mysql_user, $mysql_password, $mysql_database);

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

    $check_for_user = mysqli_query($connect,"SELECT username FROM accounts WHERE username = '".MD5($username)."'"); 
    $check_for_number = mysqli_query($connect,"SELECT phone_number FROM accounts WHERE phone_number = '".MD5($phone_number)."'");


    if(mysqli_num_rows($check_for_user) == 0 && mysqli_num_rows($check_for_number) == 0) {
        $register = mysqli_query($connect, "INSERT INTO accounts (username, password, phone_number) VALUES ('".MD5($username)."', '".MD5($password)."','". MD5($phone_number)."'"); 
    if($register) {
    echo  "registered";
    }
    else { echo "something went wrong"; 
    }
    }

     else if(!mysqli_num_rows($check_for_user) == 0) {
                echo "user_exists";
     } else if(!mysqli_num_rows($check_for_number) == 0) {

     echo "number_exists";

     }




mysqli_close($connect);

?>