0

I have spent some time looking for answers on the net and to no avail - read some of the posts, but have not seen something that is the same.

The following line is causing me an issue with the following error:

Notice: Undefined index: username in C:\xampp\htdocs\newlogin\authorise.php on line 19

The line it is associated with is the following:

$stmt->bindValue(':username',strtolower($_POST['username']));

I have included all of the code just in case. I have the username column setup in the database (MySQL)

Any advice would be great, am fairly new to this, so my apologies if there is a simple response


<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';
}

Ram Sharma
  • 8,676
  • 7
  • 43
  • 56
dabollix
  • 47
  • 4

3 Answers3

2

It means that your $_POST array doesn't have username key.

You can simply check it with 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';
    }
}

Voila no notice ;)

When you post form check if the input name is set to "username" and is not empty.

Robert
  • 19,800
  • 5
  • 55
  • 85
  • I get a blank page when I put this code in. Thought I should get the user found text – dabollix Sep 11 '14 at 13:23
  • add else { echo 'username is empty'; } you don't get data from your form as I wrote in answer check name of inputs. – Robert Sep 11 '14 at 13:43
  • It apphe ears as if the code is not getting to the if statement - have echoed inside the if statement and I am still getting a blank page. Have you somemore advice? – dabollix Sep 11 '14 at 15:04
  • It appears as if the code is not reaching the if statement with the username information, i tried it instead of the code I have been using and there is no display. I have also tried echoing inside the if statement and there is no display. Could you please help? – dabollix Sep 11 '14 at 15:13
  • maybe turn on errors and check what's happening with error_reporting(E_ALL) or ini_set('display_errors' 1) – Robert Sep 12 '14 at 08:10
0

It means either you dont have username fild in your database table or you dont have username field name in your form. Please double check your table structure and form.

Shreeraj Karki
  • 234
  • 2
  • 11
0

I have discovered that I missed out on an = sign in the login script. However, I am still the authorise page will not enter the if statement. I have put echos in and around it and they display until I put the echo inside the if statement

dabollix
  • 47
  • 4