Jump to content

[SOLVED] $_POST ERROR, please help.


unsider

Recommended Posts

<?php

$dbhost = "localhost";
$dbname = "andy";
$dbuser = "root";
$dbpass = "admin";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

echo '<pre>';
print_r($_POST);
echo '</pre>';

17. $username = $_POST['username'];
18. $password = md5($_POST['password']);

if (isset($username)) {
    echo "user var is set.";
}
if (isset($password)) {	
echo "pass var is set.";
}


$query = "select * from users where username='$username' and password='$password'";


$result = mysql_query($query);

if (mysql_num_rows($result) != 1) {

	$error = "Bad Login";
    include "loginform.php";

} else {
//session_start();

    $_SESSION['username'] = "$username";
    require_once "index.php";

} 

?>	

 

ERROR:

 

Notice: Undefined index: username in /Users/andythompson/Sites/login.php on line 17

 

Notice: Undefined index: password in /Users/andythompson/Sites/login.php on line 18

 

 

Can someone help, and if you need more code, anything, etc...just ask.

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/84553-solved-_post-error-please-help/
Share on other sites

<?php

$dbhost = "localhost";
$dbname = "andy";
$dbuser = "root";
$dbpass = "admin";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

echo '<pre>';
print_r($_POST);
echo '</pre>';

if ( isset($_POST['username']) ) {
    $username = $_POST['username'];
}
if ( isset($_POST['password']) ) {
    $password = md5($_POST['password']);
}

if (isset($username)) {
    echo "user var is set.";
}
if (isset($password)) {	
echo "pass var is set.";
}


$query = "select * from users where username='$username' and password='$password'";


$result = mysql_query($query);

if (mysql_num_rows($result) != 1) {

	$error = "Bad Login";
    include "loginform.php";

} else {
//session_start();

    $_SESSION['username'] = "$username";
    require_once "index.php";

}

 

PhREEEk

 

?>

$query = "select * from users where username='$username' and password='$password'";

 

Notice: Undefined variable: password in /Users/andythompson/Sites/login.php on line 37

 

 

 

now this is giving me problems, but i guess it has something to do with the fact im trying to address the undefined array like you said?

Since the notice was saying that at least one of those elements was empty, then your querying for one of three things:  a blank username and password, a blank username with a password, or a username with a blank password...depending on which variable is empty (username or password).

 

Echo your query before it's executed to make sure that it is populated with the values you are expecting.

Alright ill try that.

 

 

$query = "select * from users where username='$username' and password='$password'";

 

echo "$query<br>";

 

if(isset($query)) {

echo 'query is set';

}

 

select * from users where username='a' and password='0cc175b9c0f1b6a831c399e269772661'

query is set

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.