Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7665207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:30:15+00:00 2026-05-31T14:30:15+00:00

I have been trying to make a user login page that, when the user

  • 0

I have been trying to make a user login page that, when the user logs in, will redirect a user based on the user id to a specific url.

To be more specific, let’s say in the database I have 4 rows: id, username, password, redirect. After successful login it will go to a user’s specific row, grab the redirect url, and redirect the user to that url. I have made a script that will redirect the url based on the database’s redirect url, but when I add more users to the db it freezes and often does not display anything or redirects to the wrong url. Here is the code:

<?php 
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="test"; // Database name 
$tbl_name="members"; // Table name 

// Connect to server and select databse. 
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB"); 

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection) 
$myusername = stripslashes($myusername); 
$mypassword = stripslashes($mypassword); 
$myusername = mysql_real_escape_string($myusername); 
$mypassword = mysql_real_escape_string($mypassword); 
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; 
$result=mysql_query($sql); 

// Mysql_num_row is counting table row 
$count=mysql_num_rows($result); 
// If result matched $myusername and $mypassword, table row must be 1 row 
if($count==1){ 
// Register $myusername, $mypassword and redirect to file"login_success.php" 
$_SESSION['username'] = $myusername; 
$_SESSION['password'] = $mypassword; 
$result = mysql_query("SELECT redirect FROM members"); 

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
   header("Location: " . $row['redirect']); 
} 
exit(); 
} 
else { 
echo "Wrong Username or Password"; 
} 
?> 

I really appreciate any help, tutorials, or criticism. Thank you.
(Please also be descriptive in your answers I am still pretty new to web development. 😉 )

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:30:17+00:00Added an answer on May 31, 2026 at 2:30 pm

    Since you can only redirect a person one time, and you already have the redirect value from your original select query that checked for a username and password match, I would change your code to something like this:

    $sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; 
    $result = mysql_query($sql); 
    
    // Mysql_num_row is counting table row 
    $count = mysql_num_rows($result); 
    
    // If result matched $myusername and $mypassword, table row must be 1 row 
    if($count == 1){ 
        // Register $myusername, $mypassword and redirect to file"login_success.php" 
        $_SESSION['username'] = $myusername; 
        $_SESSION['password'] = $mypassword; 
    
        $result = mysql_fetch_array($result); // get the result set from the query
    
        $redirect = trim($result['redirect']); // get the redirect column's value
    
        if ($redirect == '') {
            echo "No redirect value was set!";
        } else {
            header('Location: ' . $redirect);
            exit;
        }
    } else { 
        echo "Wrong Username or Password"; 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to make a secure login for my site that I
I have been trying to make a clock that the user can set. I
I have been trying to make this to be a little jQuery plugin that
I have been trying to test my application to make sure that all the
I have been trying to make a method where the user can input a
I have been trying to make a case for using Python at my work.
I have been trying to make a div fade in evey 30sec and out
I have been trying to make the sub-menu horizontal. In my HTML it looks
I have been trying to make an init script using start-stop-daemon. I am stuck
I have been trying to make a Cross-platform 2D Online Game, and my maps

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.