Results 1 to 9 of 9

Thread: MySQL PhpMyAdmin login issues

  1. #1
    Guest

    Exclamation MySQL PhpMyAdmin login issues

    My website has a login page. I've imported code from a functioning site where the login code used to work. I've changed all the relevant details, database name etc using the advice given on the database settings. The php is working (i.e incorrect passwords are detected etc) however all that happens is the page refreshes.

    Need help!

    EDIT:
    I've spoken to some people and they suggested it could be a technical error on my hosts' side. I have exported and imported all the databases and code from another host, changed the relevant information (i.e connect.inc.php file) and it doesn't work. It should work. It works on the other host. I can create register new accounts but i can't login. All it does is refresh. ?!!?!? THIS IS URGENT PLS HELP.
    Last edited by bbelectricalsite; 01-14-2016 at 12:42 PM.

  2. #2
    karl94 is offline AlterVista Staff
    Join Date
    Jan 2015
    Posts
    573

    Default

    Could you provide the URL of the login page with some credential to test?

  3. #3
    Guest

    Exclamation Please help, I have a deadline approaching.

    Quote Originally Posted by karl94 View Post
    Could you provide the URL of the login page with some credential to test?
    Thank you for your reply. Was expecting an email notification, which is why I hadn't replied sooner.

    Website address - http://bbelectricalsite.altervista.o...ize/BBElec.php

    Username : "Bob"
    Password: "BillyBob"

    I'm doing this for a coursework piece, and really need this to work ;(

  4. #4
    karl94 is offline AlterVista Staff
    Join Date
    Jan 2015
    Posts
    573

    Default

    Can you post the PHP code in BBElec.php?

  5. #5
    Guest

    Default

    IT WORKS! KIND OF...

    HTML Code:
    <form action="tblexp.php" method="POST">
    Username: <input type="text" name="user"><br />
    Password: <input type="password" name="pass"><br /> 
    <input type="submit" value="Login" name="submit" />
    </form>
    This is the login form html code. With the code above any username or password logs in. Which obviously shouldn't happen.

    If I remove tblexp.php then the website can tell if the wrong username and password is entered through the echo function, however it doesn't redirect to the main page if the details are correct. Please help.
    Last edited by karl94; 01-15-2016 at 05:25 PM. Reason: Formatting

  6. #6
    Guest

    Exclamation

    Quote Originally Posted by karl94 View Post
    Can you post the PHP code in BBElec.php?
    Here is the code

    PHP Code:
    <?php

    if(isset($_POST["submit"])){

    if(!empty(
    $_POST['user']) && !empty($_POST['pass'])) {
    $user=$_POST['user'];
    $pass=$_POST['pass'];

    $con=mysql_connect('localhost','bbelectricalsite','') or die(mysql_error());
    mysql_select_db('my_bbelectricalsite') or die("cannot select DB");

    $query=mysql_query("SELECT * FROM users WHERE username='".$user."' AND password='".$pass."'");
    $numrows=mysql_num_rows($query);
    if(
    $numrows!=0)
    {
    while(
    $row=mysql_fetch_assoc($query))
    {
    $dbusername=$row['username'];
    $dbpassword=$row['password'];
    }

    if(
    $user == $dbusername && $pass == $dbpassword)
    {
    session_start();
    $_SESSION['sess_user']=$user;

    /* Redirect browser */

    header("Location: http://bbelectricalsite.altervista.org/materialize/tblexp.php");
    }
    } else {
    echo
    "Invalid username or password!";
    }

    } else {
    echo
    "All fields are required!";
    }
    }
    ?>
    Last edited by karl94; 01-15-2016 at 05:29 PM. Reason: Formatting.

  7. #7
    karl94 is offline AlterVista Staff
    Join Date
    Jan 2015
    Posts
    573

    Default

    If the action attribute is empty, the form will be sent to the same URL of the form's document (https://www.w3.org/TR/html5/forms.ht...sion-algorithm).
    However the problem in your code is that the PHP block is in the middle of the page, so when it gets executed the server already started writing the HTTP response and that's a problem since the headers must be sent before the body of the response.
    You have to call the header function before any output, so you should move that PHP block at the beginning of the file (and change also those echo).

  8. #8
    Guest

    Default Thank you!

    Quote Originally Posted by karl94 View Post
    If the action attribute is empty, the form will be sent to the same URL of the form's document (https://www.w3.org/TR/html5/forms.ht...sion-algorithm).
    However the problem in your code is that the PHP block is in the middle of the page, so when it gets executed the server already started writing the HTTP response and that's a problem since the headers must be sent before the body of the response.
    You have to call the header function before any output, so you should move that PHP block at the beginning of the file (and change also those echo).
    You are a blessing It works now

    My sessions still don't seem to be working. If I close the tab and go back to the page that requires a login, instead of redirecting to the login page, it lets the user through without having to input a username or password.

    Am I supposed to have some php code at the beginning of my main page (/tblexp.php) that checks to see if the user has inputted a username or password? Surely the sessions do that work?

  9. #9
    karl94 is offline AlterVista Staff
    Join Date
    Jan 2015
    Posts
    573

    Default

    Post the code of tblexp.php.

Tags for this Thread

Posting Permissions

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

SEO by vBSEO