Problem with $HTTP_POST_VARS

A

Anonymous

Guest
hi, this is a piece of my code:
Code:
if (isset($HTTP_GET_VARS['user'])) {
 $username = $HTTP_GET_VARS['user'];

    if (isset($HTTP_POST_VARS['pass'])) {
    $password = $HTTP_POST_VARS['pass'];

    $db = mysql_connect("127.0.0.1", "user", "");
    mysql_select_db("test1", $db);
    $result = mysql_query("SELECT * from users WHERE (user = '$username')",$db);
    $d_pass = mysql_result($result,0,"pass");
    if ($password != $d_pass) {

    print("<b>Password incorrect, please try again.</b>");
    login();

    } else {

     printf(mysql_result($result,0,"data"));

     exit();

     }
it works fine but it gives me this annoying notice everytime its run:
Notice: Undefined index: pass in C:\Program Files\Apache Group\Apache2\htdocs\mysql\test2.php on line 27

what do i have to do to my code to get rid of this notice?
thanks
 
nickk said:
it works fine but it gives me this annoying notice everytime its run:
Notice: Undefined index: pass in C:\Program Files\Apache Group\Apache2\htdocs\mysql\test2.php on line 27

First of all, next time help us out by telling us which line is the one referred to in the error. But I'll assume that it's one of these two lines:

Code:
    if (isset($HTTP_POST_VARS['pass'])) {
    $password = $HTTP_POST_VARS['pass'];

First of all, if you're using a recent version of PHP, just use $_POST[].. it'll save you some typing. Second, if it says 'undefined index', then it means there's no element in $HTTP_POST_VARS with the index 'pass'. It looks like you're trying to use isset() to see if such an element exists, but instead what you should be using is array_key_exists(). Give it a shot.
 
hey thanks for the help il give it a shot, but i ahve another question, i have a script that checks the username against a username/pass combination in the mysql database, now i want it to print something if it cant find the user instead of gving me an ugly error like this:
Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 2 in C:\Program Files\Apache Group\Apache2\htdocs\mysql\test2.php on line 89

code:
Code:
        $result = mysql_query("SELECT * from users WHERE (user = '$username')",$db);
          if ($result == 0) { print("<b>No such username or password</b>");
            } else {

        $d_pass = mysql_result($result,0,"pass");


          if ($password != $d_pass) {

            print("<b>Password incorrect, please try again.</b>");
            login();
 
            }

why doesnt it work?
 
Back
Top