Issue
I have a mySQL DB that contains user information. Information is added to the DB using a user registration system, which is working properly. Here's an example user (PHPmyadmin): 
Issue is that I have a PHP based 'my account' page that retrieves info about the user's account. This informaiton doesn't seem to be in sync with the MySQL when I update user information from PHPMyAdmin or even when I add new data about a user (for example, my PHP won't detect the newly-added 'RealName' field although it recognizes the 'EmailAddress' field which has been there for a while.
PHP/HTML:
<div class="modal-body">
<img src="assets/user.jpg" style="border-radius:150px;height:150px;width:150px;float:left;"><br>
<h2 class="desc" style="font-style: normal;padding:0px;margin:0px;float:left;">  <?=$_SESSION['RealName']?></h2><br><br>
<h4 class="desc" style="font-style: normal;padding:0px;margin:0px;float:left;"><i>    @<?=$_SESSION['Username']?></i></h4><br><br>
<hr>
<a href=""><p class="desc" style="font-style: normal;float:left;">    Change Profile Image...</h2></a> <a href=""><p class="desc" style="font-style: normal;float:left;">    Change Your Name...</h2></a>
</div>
<div class="modal-footer-alt"><br><br>
<h4>Account Info  </h4>
<p class="desc" style="font-style: normal;float:left;"><b>E-Mail Address: </b><?=$_SESSION['EmailAddress']?>  </p> <code style="float:left;">Private</code><br><br>
<p class="desc" style="font-style: normal;float:left;"><b>Password: </b> ●●●●●●●●●●  </p> <code style="float:left;">Private</code><br>
<h4>Bio  </h4>
<textarea rows="4" cols="40"><?=$_SESSION['Bio']?></textarea>
<h4>More  </h4>
<a href="../account/die.php"><button class="btn btn-default">Log Out</button></a><a href="../account/die.php"><button class="btn btn-default">Sign Up for Contributor Rewards</button></a>
</div>
How it appears on the webpage:
Notice that some of the info appears and other info doesn't. This isn't an issue with my HTML as if I replace the PHP with a static value, it displays fine.
This is the code I use to start the session:
<?php
session_start();
$dbhost = "PRIVATE"; // this will ususally be 'localhost', but can sometimes differ
$dbname = "PRIVATE"; // the name of the database that you are going to use for this project
$dbuser = "PRIVATE"; // the username that you created, or were given, to access your database
$dbpass = "PRIVATE"; // the password that you created, or were given, to access your database
mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());
?>
Log off code:
<?php include "base.php"; $_SESSION = array(); session_destroy(); ?>
Solution
You need to reload your $_SESSION values... This can be achieved by creating a page logout.php and having the functions session_start(); session_destroy(); in it. Your login page will need to be updated to have the correct session data as well.
Answered By - Rob W
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.