使用php会话获取Mysqli中WHERE的信息
我试图使用登录系统设置的会话从数据库中获取有关未填写表单的用户的信息 我现在使用的代码是:使用php会话获取Mysqli中WHERE的信息,php,session,mysqli,Php,Session,Mysqli,我试图使用登录系统设置的会话从数据库中获取有关未填写表单的用户的信息 我现在使用的代码是: <?php $con=mysqli_connect("127.0.0.1","user","pass","db"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($c
<?php
$con=mysqli_connect("127.0.0.1","user","pass","db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM playerdata WHERE Unique_ID = '$uid'");
while($row = mysqli_fetch_array($result)) {
$row['Unique_ID'];
$row['AC'];
?>
<b><?php echo $row['AC']; ?></b> </div>
<?php
}
mysqli_close($con);
?>
<p> </p>
Welcome to the armour coins shop! Here you can spend your hard earned coins on some shiny armour and weapons. You gain coins by leveling up in-game. You can do this by preforming laberous activities. <a href="?explain=leveling">Click here for more information about leveling</a>
<p> </p>
<form action="buy.php" method="POST" class="form-inline" style="display:inline-block;">
<input type="hidden" name="uid" value="<?php echo $_POST['uid']; ?>">
<input type="hidden" name="username" value="<?php echo $_POST['username']; ?>">
<input type="hidden" name="item" value="127">
<input type="submit" value="Buy Brynie">
<?php
}
elseif(!empty($_POST['username']) && !empty($_POST['password']))
{
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$uid = mysql_real_escape_string($_POST['uid']);
$checklogin = mysql_query("SELECT * FROM account WHERE Username = '".$username."' AND Password = '".$password."' AND Unique_ID = '".$uid."'");
if(mysql_num_rows($checklogin) == 1)
{
$row = mysql_fetch_array($checklogin);
$email = $row['EmailAddress'];
$_SESSION['Username'] = $username;
$_SESSION['Uid'] = $uid;
$_SESSION['EmailAddress'] = $email;
$_SESSION['LoggedIn'] = 1;
?>
我在代码中没有看到会话\u start(),您需要添加会话\u start(),然后才能使用会话
请确认$uid中确实有一个值。您的代码中没有任何地方可以调用
会话\u start()
。如果没有这一点,$\u SESSION
只是一个普通变量,就像其他任何变量一样,它的内容在脚本退出时将被删除。忘记添加包含SESSION start的base.php。我建议将您的整个代码升级到mysqli,因为我看到的是降低的库和改进的扩展的混合体。
$uid = ($_SESSION['Uid']) ?>
$result = mysqli_query($con,"SELECT * FROM playerdata WHERE Unique_ID = '$uid'");