普通网友 2015-12-05 01:39
浏览 146
已采纳

“mysqli_num_rows”与“mysqli_query”的输出斗争

I made a simple Login Form there are some errors in the code I guess.

Everything is working fine but I'm struggling with the MySQL(mysqli) Query part.

But here is my code first:

<?php
session_start();

if(isset($_SESSION['acuser']))
{
redirectpage();
}
else
{
if($_POST)
{   
if(isset($_POST['button']) && ($_POST['username']) && ($_POST['password']))
{
$db = 'datenbank';
$dbuser = 'root';
$dbpass = '';
$dbhost = 'localhost';

$connection = mysqli_connect($dbhost,$dbuser,$dbpass);
$selection = mysqli_select_db($connection,$db);

$username = mysqli_real_escape_string($connection,(htmlspecialchars($_POST['password'])));
$password = mysqli_real_escape_string($connection, (htmlspecialchars($_POST['password'])));
$password = md5($password);


if($connection)
{
if($selection)
{
$queryuser = "SELECT * FROM main WHERE Username = '$username'";
$result = mysqli_query($connection, $queryuser);

$checkuser = mysqli_num_rows($result);
if($checkuser)
{
$querypass = "SELECT * FROM main WHERE Username = '$username' AND Password ='$password'";
$resultpass = mysqli_query($connection,$querypass);

$checkpass = mysqli_num_rows($resultpass);
if($checkpass)
{   
$data = mysqli_fetch_array ($resultpass);

$_SESSION["acID"] = $data["Id"];
$_SESSION["acUSERNAME"] = $data["Username"];
$_SESSION["acPASSWORD"] = $data["Password"];
$_SESSION["acEMAIL"] = $data["Email"];
}

// Some else stuff
?>

I guess there is something wrong with "mysqli_query()" and "mysqli_num_rows()"!

"Mysqli_num_rows()" can't handle the output of "mysqli_query()" somehow!

Maybe i will find an answer here

  • 写回答

1条回答 默认 最新

  • dream198731 2015-12-05 01:53
    关注

    Not sure if this is the problem:

    $username = mysqli_real_escape_string($connection,(htmlspecialchars($_POST['password'])));
    

    is the username the same as the password in the database?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?