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
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

 

?>

Link to comment
Share on other sites

$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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.