所以我正在创建一个小型网站,并希望选择一个mysql行,其中行中的idu与刚刚登录到站点的用户的会话ID相同,该会话在网站的其他页面上运行良好但我对此无能为力,请参阅下面的代码
<?php
include('solutions/session.php');
$id ='';
$id= $_SESSION['id'];
$page_name = 'settings';
$con=mysqli_connect("localhost","root","usbw","company");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM payment WHERE idu='$id'");
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['wallet'] . "</td>";
echo "<td>" . $row['amount'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
和session.php看起来像这样
<?php
$connection = mysql_connect("localhost", "root", "usbw");
$db = mysql_select_db("company", $connection);
session_start();
$user_check = $_SESSION['login_user'];
$ses_sql = mysql_query("select username from wallet where username='$user_check'", $connection);
$row = mysql_fetch_assoc($ses_sql);
$login_session = $row['username'];
if (!isset($login_session)) {
header("location: index.php");
mysql_close($connection);
}
?>
答案 0 :(得分:0)
首先,您的 session.php 文件代码无法正常工作,因为您使用的是mysql_query并且还传递了导致错误使用的连接 mysqli_query()
$ses_sql = mysqli_query($con,"select username from wallet where username='".$id."' ");
$row = mysqli_fetch_assoc($ses_sql);
//then set your session variable most imortant is id which is usefull
$_SESSION['id'] = $row["id"];
其余的事情都很好
答案 1 :(得分:-1)
尝试替换此行:
$result = mysqli_query($con,"SELECT * FROM payment WHERE idu='$id'");
这一个:
$result = mysqli_query($con,"SELECT * FROM payment WHERE idu=".$id);