www.webdeveloper.com
Results 1 to 6 of 6

Thread: Login form

  1. #1
    Join Date
    Feb 2014
    Posts
    6

    Login form

    Hi I want to create a login form, but need some help with the code below because it doesn't seem working:

    <?php
    session_start();

    if(isset($_POST['submit']))
    {
    if(isset($_POST['username'], $_POST['password']))
    {
    $con=mysqli_connect("localhost","root","","sgptt");
    $username = mysqli_real_escape_string($con, $_POST['username']);
    $password = hash('sha512', $_POST['password']);
    $exists = mysqli_query($con, "SELECT COUNT(*) FROM useraccount WHERE Username = '{$username}' AND Password = '{$password}'") or die(mysqli_error($con));

    if(mysqli_fetch_array($exists, MYSQL_NUM) === 1)
    {
    echo("Login Sucessfull") ;
    }
    else
    {
    echo("Login fail");

    }
    }
    }
    ?>

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    629
    Does the code itself actually run? Do you get any message from your echos? Do you have error checking turned on and get any php messages? Put some messages in the if statements where they are 'false' (the non-existent else clauses) so you can see what may be happening.

    Help us to help you. Don't just say it's not working.

  3. #3
    Join Date
    Feb 2014
    Posts
    6
    No I didn't get any message from echos just returns a blank page. I will put some message in the if statement now. Thanks

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    629
    I find that a page that returns nothing at all usually has an error in it. Turning on error checking shows me the message.

  5. #5
    Join Date
    Feb 2014
    Location
    Viet Nam
    Posts
    32
    please check on this line:

    if(isset($_POST['username'], $_POST['password']))

  6. #6
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    629
    aubenefit - one can use multiple parms in the isset function.

    If the OP would simply turn on error checking - OR use an IDE that recognizes PHP syntax, etc. - he would find his problem is an error in his php. There is no mysqli_fetch_array function and that would show up in either his editor or in his execution.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles