dongtazu3080 2016-05-26 08:30 采纳率: 100%
浏览 7
已采纳

登录屏幕 - 不工作

I've got a login screen all setup but my php code doesn't seem to work with it. Can't find the issue either as the details I'm entering are correct but it is not displaying either of the outputs. 1 - being proceed to next page. 2 - being display message saying incorrect details. Atleast thats what I think it should be doing. My code is here;

 <?php
 session_start();
 if (isset($_POST['login'])):

 require_once('my_connect.php');
    $username=$_POST['username'];
    $password=$_POST['password'];

    $my_query="SELECT * from loanusers where username='$username' AND    password='$password'";
    $result= mysqli_query($connection, $my_query);

    if (mysqli_num_rows($result) >0):
    while ($myrow = mysqli_fetch_array($result)):

    $_SESSION['userid'] = $myrow["userid"];
    $_SESSION['username'] = $myrow["username"];
    $_SESSION['password'] = $password;
    $_SESSION['usertype'] = $myrow["usertype"];
    $_SESSION['authenticated'] = true;

    echo "<b> Hi ".$_SESSION['username']." (ID: ".$_SESSION['userid']."), You are now logged in!</b>";
    endwhile;

    //header('Location: homepage.php');

    else:
        echo "<b>Username or Password incorrect</b>";
    endif;
    mysqli_close();   

 endif; 
 require_once 'loginheader.php';

 ?>


 <html>
 <body>
 <h2>User Login</h2>
 <div id="loginp"><p>Need an Account? <a href='adduser.php'><b>Sign Up</b>  </p></a></div>


 <table>
 <form method="POST" action="homepage.php" autocomplete="off">
 <input type="text" name="username" placeholder="Username..."> 
 <br><br>
 <input type="password" name="password" placeholder="Password..."> 
 <br><br>
 <input type="submit" name="loanlogin" value="Sign In"  onclick="window.location.href='homepage.php'">
 </form> 
 </table>
 <br>
 <div id="loginp"><p>Forgot your Password?<b> Click Here</b></p></a></div>
 <body>
 <html>
  • 写回答

3条回答 默认 最新

  • dpb35161 2016-05-26 10:21
    关注

    The html post action was taking me to another page bypassing the login script.

    I changed the action to index.php and the login now displays an error if the details are incorrect and takes me to the take page if details are correct.

    Thanks All for helping

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭