我花了一些时间在网上寻找答案,但无济于事 - 阅读了一些帖子,但没有看到相同的内容。
以下行导致我出现以下错误:
Notice: Undefined index: username in C:\xampp\htdocs\newlogin\authorise.php on line 19
与其关联的行如下:
$stmt->bindValue(':username',strtolower($_POST['username']));
为了以防万一,我已经包含了所有代码。我在数据库(MySQL)中设置了用户名列
任何建议都会很好,我对此还很陌生,所以如果有一个简单的回复,我很抱歉
<小时/><title>authorise</title>
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
try
{
$dbh = new PDO("mysql:host=localhost;dbname=login_site","root","black$23");
}
catch (PDOException $e){
echo $e->getMessage();
}
$query = "select * from 'users' where LOWER ('username')=:username";
$stmt=$dbh->prepare($query);
$stmt->bindValue(':username',strtolower($_POST['username']));<--- issue is on this line
$stmt->execute();
if ($stmt->rowCount()==1){
echo'user found';
}
<小时/>
最佳答案
这意味着您的 $_POST 数组没有用户名 key 。
你可以简单地用 if 来检查
if(isset($_POST['username']))
{
$query = "select * from 'users' where LOWER ('username')=:username";
$stmt=$dbh->prepare($query);
$stmt->bindValue(':username',strtolower($_POST['username']));
$stmt->execute();
if ($stmt->rowCount()==1)
{
echo'user found';
}
}
瞧,没有通知;)
当您发布表单时,请检查输入名称是否设置为“用户名”且不为空。
关于php - 通知: Undefined index: username PHP and MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25786683/