doulvyi2172 2014-01-17 00:38
浏览 68

未定义索引:登录时(php)[重复]

I am getting this error

Notice: Undefined index: username in C:\xampp\htdocs\login.php on line 24

Notice: Undefined index: password in C:\xampp\htdocs\login.php on line 25

on this code

<?php

session_start();

$username = $_POST['username'];
$password = $_POST['password'];

if ($username&&$password)
{

$connect = mysql_connect("localhost","root","") or die ("couldn't connect");
mysql_select_db("test") or die ("couldn't find DB");

$query = mysql_query("select * FROM users WHERE username='$username'");

$numrows = mysql_num_rows($query);

if($numrows!=0)
{
//login goahead

while ($row = mysql_fetch_assoc($query))
{
   $dbusername = $row['username'];
   $dbpassword = $row['password'];

if($username==$dbusername&&$password==$dbpassword)

{
  echo "You're in! <a href='member.php'>click here to continue</a>";
  $_SESSION['username']=$username;

}
else
   echo"Incorrect Password";

}
}
else
die("That user does not exist!");



}
else
die("please enter a username and password");

?>

I have tried changing around where the if statement that checks DB username and pass that is and tried to redefine the calls but it wont work. any help will be great.

</div>
  • 写回答

1条回答 默认 最新

  • dsfhe34889789708 2014-01-17 00:56
    关注

    Your problem appears to be here:

    $dbusername = $row['username'];
    $dbpassword = $row['password'];
    

    Your SQL query seems to suggest that it is not returning any results with the row index username or password.

    ie. $row['username'] does not exist etc..

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度