PHP Error

Integers

Soon to be Developer!
Sep 22, 2012
119
7
Code:
Notice: Undefined index: username in C:\xampp\htdocs\ThisChat\verify.php on line 6

PHP:
<?php
session_start();
include 'config.php';
 
$username = $_POST['username'];
$password = $_POST['password'];
if(isset($_POST['Submit']))
{
if($username&&$password)
{
    $query = mysql_query("SELECT * FROM `users` WHERE `username`='$username'");
    $id1 = mysql_query("SELECT `id` FROM `users` WHERE `username`='$username'");
    $numrows = mysql_num_rows($query);
   
    while ($row = mysql_fetch_array($id1))
    {
        $id = $row['id'];
    }
 
 
    if($numrows!=0)
    {
      while ($row = mysql_fetch_assoc($query))
      {
          $user = $row['username'];
          $pass = $row['password'];
      }
 
      if($username==$user&&md5($password)==$pass)
      {
          $_SESSION['user']=$username;
          $_SESSION['user_id']=$id;
          header("location: index.php");
 
      }
      else
        echo "Your password is incorrect, please try again.";
 
    }
    else
      echo "The user $username does not exist";
 
}
else
  echo "Please enter your username and password.";
 
}
 
if($_SESSION['username'])
{
  header("location: index.php");
}
   
?>
 

Leon

Member
Jan 2, 2011
83
42
A form needs to be submitted to that file via POST. The error is basically saying that $_POST['username'] is non-existent.

The form needs to contain 2 inputs, one with the name as "username" and the other with a name as "password".
 

Tronscript

Member
Aug 18, 2012
93
8
This has an SQL Injection exploit, but I cbf to fix that shit right now.
PHP:
<?php
session_start();
include 'config.php';
 
if(isset($_POST['Submit'])) {
  if($username&&$password) {
  $username = $_POST['username'];
  $password = $_POST['password'];
 
    $query = mysql_query("SELECT * FROM `users` WHERE `username`='$username'");
    $id1 = mysql_query("SELECT `id` FROM `users` WHERE `username`='$username'");
    $numrows = mysql_num_rows($query);
 
    while ($row = mysql_fetch_array($id1))
    {
        $id = $row['id'];
    }
 
 
    if($numrows!=0)
    {
      while ($row = mysql_fetch_assoc($query))
      {
          $user = $row['username'];
          $pass = $row['password'];
      }
 
      if($username==$user&&md5($password)==$pass)
      {
          $_SESSION['user']=$username;
          $_SESSION['user_id']=$id;
          header("location: index.php");
 
      }
      else
        echo "Your password is incorrect, please try again.";
 
    }
    else
      echo "The user $username does not exist";
 
}
else
  echo "Please enter your username and password.";
 
}
 
if($_SESSION['username'])
{
  header("location: index.php");
}
 
?>
 

Integers

Soon to be Developer!
Sep 22, 2012
119
7
This has an SQL Injection exploit, but I cbf to fix that shit right now.
PHP:
<?php
session_start();
include 'config.php';
 
if(isset($_POST['Submit'])) {
  if($username&&$password) {
  $username = $_POST['username'];
  $password = $_POST['password'];
 
    $query = mysql_query("SELECT * FROM `users` WHERE `username`='$username'");
    $id1 = mysql_query("SELECT `id` FROM `users` WHERE `username`='$username'");
    $numrows = mysql_num_rows($query);
 
    while ($row = mysql_fetch_array($id1))
    {
        $id = $row['id'];
    }
 
 
    if($numrows!=0)
    {
      while ($row = mysql_fetch_assoc($query))
      {
          $user = $row['username'];
          $pass = $row['password'];
      }
 
      if($username==$user&&md5($password)==$pass)
      {
          $_SESSION['user']=$username;
          $_SESSION['user_id']=$id;
          header("location: index.php");
 
      }
      else
        echo "Your password is incorrect, please try again.";
 
    }
    else
      echo "The user $username does not exist";
 
}
else
  echo "Please enter your username and password.";
 
}
 
if($_SESSION['username'])
{
  header("location: index.php");
}
 
?>

Ok thanks for telling me this.
 

Li1M0ST3Rz

I <3 Bianca
Sep 13, 2010
269
166
A form needs to be submitted to that file via POST. The error is basically saying that $_POST['username'] is non-existent.

The form needs to contain 2 inputs, one with the name as "username" and the other with a name as "password".
well he means like this:

HTML:
<input type="text" name="username" size="45" maxlength="20" class="inputbox" />
<input name="password" type="password" size="45" maxlength="20" class="inputbox" />
 

Users who are viewing this thread

Top