我的值正在保存到数据库中,但是当我重新加载它时如何将它们保留在页面上?
这是代码。
<div class="wrapper">
<div class="submissions">
<div class="logo-logo"><h2>Quotr.</h2>
<div class="checkboxes"><?= !empty($_GET['x']) ? $_GET['x'] : '' ?>
</div>
</div>
<?php $actual_quote = (isset($_GET['actual_quote']) ? $_GET['actual_quote'] : ''); ?>
<div class="top-submit"><?php echo '“' . $actual_quote . '”'; ?>
</div>
<?php $poster = (isset($_GET['poster']) ? $_GET['poster'] : ''); ?>
<div class="poster"><?php echo '-' . $poster; ?>
<div class = "like">
<a href = "javascript:countClicksLike();" class = "btn btn-large" style = "color:green;">Like</a>
<p id = "like" style = "color:green;">0</p>
</div>
<div class = "dislike">
<a href = "javascript:countClicks();" class = "btn btn-large" style = "float:right; color:red;">Dislike</a>
<p id = "dis" style = "color:red;">0</p>
</div>
</div>
<!-- if there's an issue it may be this aswell-->
<?php
define('DB_NAME', 'submissions');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if(!$db_selected) {
die('Cannot use' . DB_NAME . ': ' . mysql_error());
}
$sql = "INSERT INTO submissions (poster, actual_quote) VALUES ('$poster', '$actual_quote')";
if(!mysql_query($sql)) {
die('Error:' . mysql_error());
}
mysql_close();
?>
接收代码并将其存储在数据库中。
我希望它留在网页上,它是保存的,我知道它是,但我如何将它保留在页面上?
答案 0 :(得分:0)
一种简单的方法是将您的值存储在$ _SESSION中,以便稍后在页面上检索它们。
session_start();
$_SESSION['x'] = $_GET['x'];
echo $_SESSION['x'];
Session Variables适用于特定用户的所有页面。您应该在将变量用于以下目的后取消设置:
session_start();
unset($_SESSION['x']);