Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Banned
    Join Date
    Aug 2002
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    username and password problem

    username and password problem
    Hi how are yo doing? I try to run this program,but it is not working. When I input username and password, the next page should come up " Welcome back $user". However, it doesn't show anything.

    Please help me this script

    My php is 4.2

    Here is codes


    <html>
    <body></body>

    <?php
    if (isset($_POST['formSubmitted']) AND $_POST['formSubmitted'] == "yes"){
    $con = mysql_connect("localhost","itohideo","1234");
    if(!$con) {
    print("Fail DB Connection<br>\n");
    exit;
    }
    if(!mysql_select_db("itohideo")) {
    print("Fail DB Selection<br>\n");
    exit;
    }

    $username=$_POST['username'];
    $password=$_POST['password'];
    $password=md5($password);
    $sql="select * from pk where username='$username' and password='$password'";

    if(!mysql_query($sql))
    {

    echo"Username or Password is incorrect. Please try again.";
    exit();

    }
    else

    {

    $row=mysql_fetch_array($result);
    extract($row);
    echo"welcome back<strong>".$username."</strong>";
    }

    }

    ?>
    Login:
    <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
    <input type="text" name="username" size="23"><br>
    <input type="password" name="password" size="23"><br>
    <input type="submit" value="Send" name="submit">
    <?
    {}
    ?>
    </body>
    </html>


    Thank you very much

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I suppose this form is calling the same page again, as indicated by you using $_SEVER['PHP_SELF']. The problem might lie in this line:

    PHP Code:
    if (isset($_POST['formSubmitted']) AND $_POST['formSubmitted'] == "yes"){ 
    So you are checking if a POST variable named "formSubmitted" exists and if it has the value "yes". Only that in your form, there is no field named "formSubmitted". So the code can't execute, since it does not pass this first check.

    Try changing the above line to

    PHP Code:
    if (isset($_POST['submit']) AND $_POST['submit'] == "Send"){ 
    That corresponds to the submit button of your form and should at least make the script pass the first check.

  • #3
    Banned
    Join Date
    Aug 2002
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help again thanks

    still not working
    Hi how are you

    YOu are right? Here is a problem

    if (isset($_POST['formSubmitted']) AND $_POST['formSubmitted'] == "yes"){

    chaged like this


    if (isset($_POST['submit']) AND $_POST['submit'] == "Send"){


    but it has warning

    my php editor says
    "Notice: Undefined variable: result in c:\itohideo\ito5.php on line 32

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\itohideo\ito5.php on line 32

    Warning: extract() expects first argument to be an array in c:\itohideo\ito5.php on line 33"

    I just want to show "welcome back username" when I click send, I just don't want to show form(text from) again.

    Please help me

    Thank you for your time

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you look closely enough at line 32, you'll see that $result is used, but that variable has not been defined previously. So all other functions have to fail, since you want to operate on an resultset that is not reachable by $result.

    Tip: Look at the line with mysql_query(), and compare that to the example at http://se.php.net/manual/en/function.mysql-query.php

  • #5
    Banned
    Join Date
    Aug 2002
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    still don't get it

    I try to do every means but not working

    I read it but I don't get it.


    Please fix my codes if you can

    thanks very much

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I won't give up; you will find the error yourself:

    Your line 32:

    PHP Code:
    if(!mysql_query($sql)) 
    The line of the example in the manual:

    PHP Code:
    $result mysql_query("SELECT my_col FROM my_tbl")
        or die (
    "Invalid query"); 
    There's something different, obviously. And in your code, you miss a variable named $result later in your script.

  • #7
    Banned
    Join Date
    Aug 2002
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    not working

    I am sorry to ask you again

    I changed like this

    $result=mysql_query($sql) or die ("Invalid query");

    $row=mysql_fetch_array($result);
    extract($row);
    echo"welcome back<strong>".$username."</strong>";

    but my php editor says"Warning: extract() expects first argument to be an array in c:\itohideo\ito6.php on line 29"

    I can't find my mistake and run this porgram. When I input different username and password, it still comes up "Welcome back username" It should come up " Invalid query"

    I tried to run this program so many times, but not working

    Please help me

    thanks

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Now that's strange. I thought the last error would be the missing $result variable, but now it seems like your query gets executed correctly, but no result set gets returned. Have you made sure the query is correct, i.e. when you run this query in phpMyAdmin, do you get a result set or "no rows returned"?

    You can check that with doing

    PHP Code:
    $result = ..... // your query here

    if ($result) {
    $numRows mysql_num_rows($result);
    echo 
    "rows" $numRows;
    } else {
    echo 
    "no rows returned";

    Check also that the column containing the md5ived password is of a text type and long enough to accomodate the whole hash string.

  • #9
    Banned
    Join Date
    Aug 2002
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    database

    my query is like this


    username itohideo
    password 1234

    that command is insert into pk (username,password) values('itohideo','1234)

    I created my query like this

    is that ok

    thanks you very much

  • #10
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No, if I shall take this query literally, it's not correct:

    Code:
    insert into pk (username,password) values('itohideo','1234)
    Your password starts as a string but doesn't get terminated by a single quote. I really doubt that this query worked, but maybe it's just a copy-paste error.

    After all, what did the code tell I posted above? And most importantly, if you are inserting the password as plain text, why do you compare it against a md5() treated version of it in your php script?

  • #11
    Banned
    Join Date
    Aug 2002
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi how are you doing? Thank you for helping me.

    actually, i don't know this part $password=md5($password);

    You said My query is wrong, so how should I fix it.

    I tried as eveybody said

    but not working

    I think that my query is wrong.


    Please help me

    Thanks all

  • #12
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by 0810
    actually, i don't know this part $password=md5($password);
    Before you use code you don't understand, you should at least read up on this function in the very detailed manual:
    http://se.php.net/manual/en/function.md5.php

    You said My query is wrong, so how should I fix it.
    I said already how to fix it, read my post carefully again.

    I think that my query is wrong.
    Which one now and why do you think it's wrong? Something you haven't told us by now?

  • #13
    Banned
    Join Date
    Aug 2002
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    not working

    Hi how are you doing mordred? Thanks for helping all the time.

    first i did your way as you told me

    $result = mysql_query($sql);
    if ($result) {
    $numRows = mysql_num_rows($result);
    echo "rows" . $numRows;
    } else {
    echo "no rows returned";
    }


    but this code didn't work. When I input username and password, just blank my texts. (like reset). Nothing happened.


    insert into pk (username,password) values('itohideo','1234')

    I just forgot single quote. That's it

    My query desn't match with database so it didn't work.

    also I am using wrong codes Here it is

    $password=md5($password);

    Calculates the MD5 hash of str using


    I try to think.

    Please gide my script

    Thanks mordred

  • #14
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: not working

    Originally posted by 0810
    but this code didn't work. When I input username and password, just blank my texts. (like reset). Nothing happened.
    I don't understand what you mean with "texts" and "reset". All that the code above should do was to print whether rows were returned or not. If this message does not appear, than there was an error in your SQL query. Use

    PHP Code:
    if (!$result) {
    echo 
    "Query: " $sql "<br>";
    echo 
    mysql_error(); 

    and look at the error message. They are usually very helpful for debugging.

    And of course, comparing a md5()-hashed password to a plain text password never gives you a match, so there can't be any rows returned even if the query itself works properly.

  • #15
    Banned
    Join Date
    Aug 2002
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    not really

    Hi how are you?

    I did whatever you told me, but it is not working

    I fixed as much as I can

    Here is codes


    <html>
    <body></body>

    <?php
    if (isset($_POST['formSubmitted']) AND $_POST['formSubmitted'] == "yes")
    // WHY NOT: if($_POST['formSubmitted'] == "yes')
    {
    $con = mysql_connect("localhost","itohideo","1234");
    if(!$con)
    {
    print("Fail DB Connection<br>\n");
    exit;
    }
    if(!mysql_select_db("itohideo"))
    {
    print("Fail DB Selection<br>\n");
    exit;
    }

    $username=$_POST['username'];
    $password=$_POST['password'];


    $sql="SELECT * FROM pk WHERE username='$username' AND password='$password'";

    $result = mysql_query($sql);
    if (!$result) {
    echo "Query: " . $sql . "<br>";
    echo mysql_error();
    }

    else
    {
    $row=mysql_fetch_array($result);
    $username = $row["username"]; // <- CHANGED
    echo"welcome back<strong>".$username."</strong>";
    }



    }


    ?>

    Login:

    <form action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post">

    <input type="text" name="username" size="23"><br>
    <input type="password" name="password" size="23"><br>
    <input type="submit" value="Send" name="submit">
    <input type='hidden' name='formSubmitted' value='yes'>
    </form>
    <?
    {}
    ?>
    </body>
    </html>


    Please look at it

    Thank you for helping me


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •