Php login cant go to the other pages

Hello I am creating a login system with registration. On my index page i have redirected to another pages but they don work. Kindly assist.Thanks.

when click login and signup it still stays on the same page.

My index page

Homepage

User Authenticatication System

<?php include_once "resource/database.php" ?>

You are currently not signin Login Not yet a member? Signup

We are here to help, but, you did not show us any code yet.
You just show one include. which of course we can not see as it is on your system.
If you want our help, please show some code inside of the correct tags. (Either quotes or preformatted)
And also ask questions that pertain to the code and we will help you fix it.

Now, normally if you post the userid and password from a login form, you post back to the same page.
Then, in the PHP code at the top of the page, it checks the database for the valid user and password.
Then, still in the PHP code at the top, if all is correct it redirects to the home page for that user. This
is handled using a header command like this: header(“Location: home.php”); Or whatever page name.
Not sure if this is what you are asking for, but, without your code and direct questions, well…

my include file database.php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "user_login";

try {
	//creating connection to mysql
    $dbh = new PDO("mysql: host=$servername;dbname=user_login", $username, $password);
    // set the PDO error mode to exception
    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
   
    }
catch(PDOException $e)
    {
    echo "Connection failed: " . $e->getMessage();
    exit;
    }
?>```

If php cant go to the other page i guess i am doing it wrong then...because when i click login or signup on the url it gives me![Capture|271x29](upload://r0AYayHb4WL58bFY2FugH1YTxyY.png) but stays on the same page.

How do you go about it from there....

Well, that is PDO code to create a connection to a database. It let’s you connect to your tables so that you can do whatever you want to do from there on. This is really just step #1 in a login system.
The steps needed to create a login system is something like this:

Create a form in HTML to allow the user to type in a username and password and include a submit button.
In the PHP code, connect to your database (as you did above.)
Get the user’s input from the posted form.
Use the user’t inputs to query the database table and retrieve their data.
If the data does not match their records in the database, you throw out errors on the display for them to fix.
If the data matches, you send them to another page. This is usually done using a “header()” function.
The header function is something like: header(“Location: homepage.php”); to send them to the correct page if their username and password are correct.

Not really sure what your question is. You showed us just the connection part of your code. Do you have the rest of the page completed? If you need a complete login system, we can help you as they are quite easy to code.

If you are looking for an entire login example, I found this one that covers just about everything you would need. You can download their entire sample and it might save you some time. They explain all parts of the system as I had listed above. Might save you some time to see how others have done it. Or just post the part of your code that is failing and we can assist you here.
Full PDO login-registration system tutorial

Thanks @ErnieAlex …for the steps which I did the step one, then I was wondering why does it not go to the other pages i created, but you’ve cleared it up.

Also I changed from an absolute path instead of a relative path and it worked.

Thanks for the Help!

Great! We are here if you run into another issue. Just open a new post.

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service