unsider Posted January 4, 2008 Share Posted January 4, 2008 <?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. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted January 4, 2008 Share Posted January 4, 2008 <?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 ?> Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted January 4, 2008 Share Posted January 4, 2008 phreeek's solution will prevent the notices from being displayed, however they are "just" notices, not errors. Php is telling you that you are trying to address an array element that doesn't exist. Quote Link to comment Share on other sites More sharing options...
unsider Posted January 4, 2008 Author Share Posted January 4, 2008 Ya I was looking to remove the notices, but I wasn't sure how to correct it. still learning Quote Link to comment Share on other sites More sharing options...
unsider Posted January 4, 2008 Author Share Posted January 4, 2008 $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? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted January 4, 2008 Share Posted January 4, 2008 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. Quote Link to comment Share on other sites More sharing options...
unsider Posted January 4, 2008 Author Share Posted January 4, 2008 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 Quote Link to comment Share on other sites More sharing options...
revraz Posted January 4, 2008 Share Posted January 4, 2008 And no error right? Quote Link to comment Share on other sites More sharing options...
unsider Posted January 4, 2008 Author Share Posted January 4, 2008 Correct. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.