【发布时间】:2015-07-28 14:28:53
【问题描述】:
我有一个包含用户信息的 mySQL 数据库。使用正常工作的用户注册系统将信息添加到数据库中。这是一个示例用户 (PHPmyadmin):
问题是我有一个基于 PHP 的“我的帐户”页面,可以检索有关用户帐户的信息。当我从 PHPMyAdmin 更新用户信息时,甚至当我添加有关用户的新数据时,此信息似乎与 MySQL 不同步(例如,我的 PHP 不会检测到新添加的“RealName”字段,尽管它识别已存在一段时间的“电子邮件地址”字段。
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>
它在网页上的显示方式: 请注意,某些信息会出现,而其他信息不会。这不是我的 HTML 的问题,就像我用静态值替换 PHP 一样,它显示正常。
这是我用来启动会话的代码:
<?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());
?>
注销代码:
<?php include "base.php"; $_SESSION = array(); session_destroy(); ?>
【问题讨论】:
-
您正在从会话中提取数据。您的代码是否会在每次网页浏览时更新会话值?
-
看起来页面正在显示来自会话的信息,而不是直接来自数据库。您能否将从数据库中获取它的代码发布到会话中?
-
不,它没有。但是,我已经尝试注销并重新登录 - 这不应该终止会话吗?
-
注销不会终止会话。会话应该被明确地销毁
session_destroy() -
请注意,
mysql不再受支持。尝试改用mysqli或pdo。
标签: php mysql mysqli phpmyadmin