Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.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 SQL命令在页面执行时失败_Php_Mysql - Fatal编程技术网

Php SQL命令在页面执行时失败

Php SQL命令在页面执行时失败,php,mysql,Php,Mysql,刚刚在phpmyadmin上测试了SQL命令,它是成功的 但是在php代码的页面中,仍然出现了一个错误 错误: 从成员数据中选择* 我的SQL php代码: <?php $hostname_connSQL = "localhost"; $database_connSQL = "member"; $username_connSQL = "root"; $password_connSQL = "pooleasee"; $co

刚刚在phpmyadmin上测试了SQL命令,它是成功的

但是在php代码的页面中,仍然出现了一个错误

错误: 从
成员数据中选择*

我的SQL php代码:

<?php
       $hostname_connSQL = "localhost";
       $database_connSQL = "member";
       $username_connSQL = "root";
       $password_connSQL = "pooleasee";
       $connSQL = mysqli_connect($hostname_connSQL, $username_connSQL,        $password_connSQL) or die('Error:' .mysqli_error($connSQL)); 
       mysqli_query($connSQL,"SET NAMES utf8")
?>
<?php
      header("Content-Type: text/html; charset=utf-8");
      require_once("connSQL.php");
      session_start();
      if(isset($_SESSION["m_username"]) && ($_SESSION["m_username"]!=""))
  {
      header("Location: membercenter.php");   
  }  
      if(isset($_POST["m_username"]) && isset($_POST["m_password"]))
  {
      $sql = "USE `member`; SELECT * FROM `memberdata`='".$_POST["m_username"]."'";
$RecLogin =  mysqli_query($connSQL,$sql)or die('Error:' .mysqli_error($connSQL)); 
  }
    $row_RecLogin = mysqli_fetch_assoc($RecLogin);
    $m_username = $row_RecLogin["m_username"];
    $m_password = $row_RecLogin["m_password"];
if($_POST["m_password"]==$m_password)
  {
    $_SESSION["m_username"] = $m_username;
    if(isset($_POST["rememberme"]) && ($_POST["rememberme"]=="true")) 
  {
    setcookie("m_username", $_POST["m_username"], time()+365*24*60*60);
    setcookie("m_password", $_POST["m_password"], time()+365*24*60*60);
  } else 
  {
    if(isset($_COOKIE["m_username"])) 
    {
      setcookie("m_username", $_POST["m_username"], time()-100);
      setcookie("m_password", $_POST["m_password"], time()-100);
    }
    }
    {   
      header("Location: membercenter.php");
    }
    } 
      else 
    {
      header("Location: index.php?loginFail=true");
    }
?>

我的登录php代码:

<?php
       $hostname_connSQL = "localhost";
       $database_connSQL = "member";
       $username_connSQL = "root";
       $password_connSQL = "pooleasee";
       $connSQL = mysqli_connect($hostname_connSQL, $username_connSQL,        $password_connSQL) or die('Error:' .mysqli_error($connSQL)); 
       mysqli_query($connSQL,"SET NAMES utf8")
?>
<?php
      header("Content-Type: text/html; charset=utf-8");
      require_once("connSQL.php");
      session_start();
      if(isset($_SESSION["m_username"]) && ($_SESSION["m_username"]!=""))
  {
      header("Location: membercenter.php");   
  }  
      if(isset($_POST["m_username"]) && isset($_POST["m_password"]))
  {
      $sql = "USE `member`; SELECT * FROM `memberdata`='".$_POST["m_username"]."'";
$RecLogin =  mysqli_query($connSQL,$sql)or die('Error:' .mysqli_error($connSQL)); 
  }
    $row_RecLogin = mysqli_fetch_assoc($RecLogin);
    $m_username = $row_RecLogin["m_username"];
    $m_password = $row_RecLogin["m_password"];
if($_POST["m_password"]==$m_password)
  {
    $_SESSION["m_username"] = $m_username;
    if(isset($_POST["rememberme"]) && ($_POST["rememberme"]=="true")) 
  {
    setcookie("m_username", $_POST["m_username"], time()+365*24*60*60);
    setcookie("m_password", $_POST["m_password"], time()+365*24*60*60);
  } else 
  {
    if(isset($_COOKIE["m_username"])) 
    {
      setcookie("m_username", $_POST["m_username"], time()-100);
      setcookie("m_password", $_POST["m_password"], time()-100);
    }
    }
    {   
      header("Location: membercenter.php");
    }
    } 
      else 
    {
      header("Location: index.php?loginFail=true");
    }
?>

您的查询语法不正确,
其中缺少columnName
。还始终使用
mysqli\u real\u escape\u字符串对值进行转义

Incorrect Syntax:
$sql = "SELECT * FROM `memberdata`='".$_POST["m_username"]."'";

Correct Syntax:
$sql = "SELECT * FROM `memberdata` WHERE m_username='".mysqli_real_escape_string($connSQL, $_POST["m_username"])."'";
将sql语法更改为

$sql = "SELECT * FROM memberdata WHERE `m_username`='" . $_POST["m_username"] . "'";

谢谢你的回答,我会试试的谢谢你的回答,我会试试的