Problem with $HTTP_POST_VARS

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

nickk
New php-forum User
New php-forum User
Posts: 36
Joined: Sat Nov 29, 2003 6:57 am

Problem with $HTTP_POST_VARS

Postby nickk » Sat Nov 29, 2003 8:20 am

hi, this is a piece of my code:

Code: Select all

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

User avatar
swirlee
Moderator
Moderator
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back
Contact:

Re: Problem with $HTTP_POST_VARS

Postby swirlee » Sat Nov 29, 2003 2:03 pm

nickk wrote: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: Select all

    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.

nickk
New php-forum User
New php-forum User
Posts: 36
Joined: Sat Nov 29, 2003 6:57 am

Postby nickk » Sat Nov 29, 2003 2:25 pm

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: Select all

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


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest