Passing data from one page to another and back

Codes here !

Moderators: macek, egami, gesf

Snaek
New php-forum User
New php-forum User
Posts: 11
Joined: Sat Dec 29, 2012 6:02 pm

Passing data from one page to another and back

Postby Snaek » Sat Apr 13, 2013 5:09 pm

Hello

I am making a simple login form using PHP and MySQL on my computer.

I have it so the user and register with a username, password, and an email and that information gets stored in a database i have created.

The the user can login using their username and password. When the user has successfully logged in, they go to their 'profile' page which has nothing on it right now except a link to see their account settings. at the top left hand corner i have their username which they can click to go to their accounts page. in the accounts page, again at the top left hand corner, it says, "username's account" and the user can see/change their username, password, or email. So far, everything works correctly. Beside the "username's account" link, there is another link which the user can click to go BACK to their "profile" but the username, password and email to not get passed to that webpage.

The following are parts of code from each of the files used (everything else is irrelevant):

Code: Select all

/* login.html */
<form action="main.php" method="post">
<table id="logTable" style="margin: 0px auto;">
<tr><td colspan="2" align="center"><b>Login Here</b></td></tr>
<tr><td align="right">Username:</td><td><input type="text" name="username" /></td></td></tr>
<tr><td align="right">Password:</td><td><input type="password" name="password" /></td></td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Login" /></td></tr>
</table>
</form>

/* main.php */
session_start();
$_SESSION['user'] = $_POST['username'];
$_SESSION['pass'] = $_POST['password'];
$_SESSION['email'] = $_POST['email'];


<div id="top-bar">
<ul>
<li><a href="account.php"><?php echo $_SESSION['user']; ?></a></li>
</ul>
</div> <!-- end top-bar div -->

/* account.php */
<?php
session_start();
?>
<div id="top-bar">
<ul>
<li><a href="account.php" style="background: #EEE;"><?php echo $_SESSION['user']; ?>'s Account</a></li>
<li><a href="main.php" style="background: #EEE;"><?php echo $_SESSION['user']; ?>'s Profile</a></li>
</ul>
</div> <!-- end top-bar div -->


<li><a href="main.php" style="background: #EEE;"><?php echo $_SESSION['user']; ?>'s Profile</a></li>

^^ this is the part where if you click that link, it doesn't pass user, pass, and email variables to 'main.php'


Any help is appreciated. Thanks.

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Passing data from one page to another and back

Postby johnj » Sun Apr 14, 2013 7:54 pm

It is not passing because when the control is back to the main page you are getting the user, pass and email from the $_ post array.

User avatar
sandeep605085
New php-forum User
New php-forum User
Posts: 44
Joined: Tue Feb 26, 2013 6:00 am
Location: Mindfire Solutions
Contact:

Re: Passing data from one page to another and back

Postby sandeep605085 » Mon Apr 15, 2013 2:26 am

Johnj is right.
let me explain you in detail.

From login.html you are submitting the form to main.php where it is storing the posted username, email and password in session(the posted data are coming from login.html).

from account.php you are calling the main.php where it storing the posted username, email and password in session but there is no posted data(username,password,email) coming from account.php so it is making the session variable's value as blank.

you need to:
1. post the data from account.php to main.php.
OR
2. check in main.php that if session values are not set than set it else do not do anything.
OR
3. use a different scirpt which only set the session and call main.php to only use it.

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Passing data from one page to another and back

Postby egami » Tue Apr 16, 2013 1:28 pm

investigate _SESSION

Snaek
New php-forum User
New php-forum User
Posts: 11
Joined: Sat Dec 29, 2012 6:02 pm

Re: Passing data from one page to another and back

Postby Snaek » Tue Apr 16, 2013 3:34 pm

Alright thanks guys. Using the isset function solved the problem.


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 0 guests