PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 1, 2022

[FIXED] PHP Not 'Syncing' with MySQL DB?

 February 01, 2022     mysql, mysqli, php, phpmyadmin     No comments   

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): enter image description here

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;">&nbsp <?=$_SESSION['RealName']?></h2><br><br>
        <h4 class="desc" style="font-style: normal;padding:0px;margin:0px;float:left;"><i>&nbsp &nbsp @<?=$_SESSION['Username']?></i></h4><br><br>
        <hr>
        <a href=""><p class="desc" style="font-style: normal;float:left;">&nbsp &nbsp Change Profile Image...</h2></a> <a href=""><p class="desc" style="font-style: normal;float:left;">&nbsp &nbsp Change Your Name...</h2></a>
        </div>
        <div class="modal-footer-alt"><br><br>
        <h4>Account Info &nbsp</h4>
        <p class="desc" style="font-style: normal;float:left;"><b>E-Mail Address: </b><?=$_SESSION['EmailAddress']?> &nbsp</p> <code style="float:left;">Private</code><br><br>
        <p class="desc" style="font-style: normal;float:left;"><b>Password: </b> ●●●●●●●●●● &nbsp</p> <code style="float:left;">Private</code><br>
        <h4>Bio &nbsp</h4>
        <textarea rows="4" cols="40"><?=$_SESSION['Bio']?></textarea>
        <h4>More &nbsp</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: enter image description here 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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing