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 7419987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:09:46+00:00 2026-05-29T08:09:46+00:00

I am using a PHP code from several different files that validates a log-in

  • 0

I am using a PHP code from several different files that validates a log-in then redirects the user to a success page. On the page I would like to welcome the user and then give them a link that redirects them to their personal service page.

This is the validation code

<?php
$host="host"; // Host name 
$username="admin"; // Mysql username 
$password="********"; // Mysql password 
$db_name="users"; // 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

// Check if Remember Me is Checked
if (isset($_POST['remember'])) {
    $remember = $_POST['remember'];
    if ($remember == 'rememberme') {
        $remember = 'checked';
    }
}
if($remember='checked' && $count==1){
    setcookie("extendloginwwd", "$myusername", time()+50400);
    // Register $myusername, $mypassword and redirect to file
"http://mydomain.co.cc/php/login_success.php"
    $_SESSION['username'] = "myusername";
    $_SESSION['password'] = "mypassword";
    header("location:http://mydomain.co.cc/php/login_success.php");
}
elseif($count==1){
    // Register $myusername, $mypassword and redirect to file
"http://mydomain.co.cc/php/login_success.php"
    $_SESSION['username'] = "myusername";
    $_SESSION['password'] = "mypassword";
    header("location:http://mydomain.co.cc/php/login_success.php");
}
else {
    echo "Wrong Username or Password";
}
?>

That works fine I have no problems with it. The login_success.php file is the trouble maker.

<?php
session_start();
?>
<!Doctype HTML>
<html>
    <head>
        <title>Login Success</title>
        <link rel="stylesheet" type="text/CSS" href="http://mydomain.co.cc/common.css">
        <?php 
            $user=$username;
            $userdir="http://wolffwebdesign.co.cc/$user";
        ?>
    </head>
    <body>
        <h1>Login Successfull!</h1>
        <p>Welcome <?php echo "$user"?>! Click <?php echo "<a href=$userdir>here</a>";?> to visit your service page to see how we are doing!
    </body>
</html>

Let’s say that $myusername=”john”. I would want the page to display something like:

Welcome John! Click here to visit your
service page to see how we are doing!

Notice it says the username and also the link leads to mydomain.co.cc/john

Instead I get something like:

Welcome ! Click here to visit you service page to
see how we are doing!

Notice it does not says the username and the link leads back to my homepage.

Thank you for any help provided.

  • 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-29T08:09:47+00:00Added an answer on May 29, 2026 at 8:09 am

    Yes because you put like this $username=$user and you do not initialize $user anywhere. To initializae $user you should do $user=$username but keep in mind that $username is actually the username from the mysql database.

    In PHP

    $variable (before = means this gets the value) = $value (after = means this is the value to be taken)

    Better do $user = $_SESSION['username']

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using php I want to load XML files from several websites and want to
I'm trying to get character data from www.wowarmory.com using PHP and cURL. The code
My PHP code is split between many files, and often I find myself using
I am using php code to query to a database and the results will
I am using following PHP code to connect to MS Access database: $odb_conn =
I am using this php code: exec(unrar e file.rar,$ret,$code); and getting an error code
I am using this PHP code: if (isset($_GET['c'])) { $pages = array(home, upload, signup);
I am using following PHP code for trigger creation but always get error, please
I'm currently using the following PHP code: // Get all subordinates $subords = array();
I'm detecting @replies in a Twitter stream with the following PHP code using regexes.

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.