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

  • SEARCH
  • Home
  • 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 8738217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:41:29+00:00 2026-06-13T10:41:29+00:00

This should be an easy PHP mySQL question (I’m assuming it’s sort of PHP

  • 0

This should be an easy PHP mySQL question (I’m assuming it’s sort of PHP and mySQL 101 but I’m having trouble finding an answer)…

I have a registration form I’ve created and when the form is filled out and submitted it posts to a register_user.php page. The code on that page is this:

<?php
$con = mysql_connect("my_host","my_username","my_password");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

// username and password sent from form
//NEVER Remove the mysql_real_escape_string. Else there could be an Sql-Injection!
$firstname=mysql_real_escape_string($_POST['firstname']);
$lastname=mysql_real_escape_string($_POST['lastname']);
$email=mysql_real_escape_string($_POST['email']);
$password=mysql_real_escape_string($_POST['password']);

$sql="INSERT INTO my_table (firstName, lastName, email, password)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[email]', '$_POST[password]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

  session_start();
  // Register $myusername, $mypassword and redirect to file "profile.php"
  $_SESSION['firstname']='$_POST[firstname]';
  $_SESSION['lastname']='$_POST[lastname]';
  $_SESSION['email']='$_POST[email]';
  $_SESSION['password']='$_POST[password]';
  header("location:profile.php");
?>

As you can see, it redirects to a page called profile.php . On profile.php I’m trying to echo out the session variables by saying:

<?php echo "Hello". $_SESSION['firstname']; ?>

I’m assuming the variable loses it’s value upon the redirect from register_user.php to profile.php (at least this is what I gather from my research thus far). I’m thinking I have to use session_start(); on the profile.php to declare the variables again but I don’t know how to set the variables to the appropriate values. In register_user.php I was able to use the post values from the form on the previous page but by the time it redirects to profile.php I can no longer do that.

Can someone please explain how I can retrieve those values on profile.php? (again I have a feeling this is a very basic question but I’m still learning so be gentle haha 🙂 )

  • 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-06-13T10:41:30+00:00Added an answer on June 13, 2026 at 10:41 am

    You are using single quote around $_POST and hence your values are not applied to $_SESSION and you were missing quotes inside

    $_POST['value']
    -------^-----^
    
    $_SESSION['firstname'] = $_POST['firstname'];
    

    And always declare session_start(); on the top of the page and ofcourse you need to declare session_start(); on the other page before you echo out the session value

    Moreover use mysqli_() instead of mysql_()

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

Sidebar

Related Questions

This should be an easy question - but I'm having a hard time figuring
It seems this should be easy but I'm having a lot of difficulty using
I don't understand why this is not working. It should be very easy. upload.php
This should be easy (at least no one else seems to be having a
This should be easy to find out but I can't seem to find it
OK, I'm feeling like this should be easy but am obviously missing something fundamental
This should be an easy problem but... I need to format a currency for
This seems like it should be so easy but I am not getting an
This should be a very easy thing to do but I can't find a
Sorry if this question may seem easy to some but i cannot seem to

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.