如何使用php在sql中使用会话变量
我在显示登录用户添加的文件时遇到问题。 我不知道如何将变量正确地传递给sql查询。 有人能帮我吗 目前,代码如下所示:如何使用php在sql中使用会话变量,php,sql,session,variables,Php,Sql,Session,Variables,我在显示登录用户添加的文件时遇到问题。 我不知道如何将变量正确地传递给sql查询。 有人能帮我吗 目前,代码如下所示: <?php include_once 'dbconnect.php'; ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>File Uploading With PHP and MySql</title
<?php
include_once 'dbconnect.php';
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>File Uploading With PHP and MySql</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="header">
<label>File Uploading With PHP and MySql</label>
</div>
<div id="body">
<table width="80%" border="1">
<tr>
<th colspan="4">your uploads...<label><a href="index.php">upload new files...</a></label></th>
</tr>
<tr>
<td>File Name</td>
<td>File Type</td>
<td>File Size(KB)</td>
<td>View</td>
</tr>
<?php
$sql="SELECT * FROM files";
$result_set=mysql_query($sql);
while($row=mysql_fetch_array($result_set))
{
?>
<tr>
<td><?php echo $row['file'] ?></td>
<td><?php echo $row['type'] ?></td>
<td><?php echo $row['size'] ?></td>
<td><a href="uploads/<?php echo $row['file'] ?>" target="_blank">view file</a></td>
</tr>
<?php
}
?>
</table>
</div>
</body>
</html>
用PHP和MySql上传文件
用PHP和MySql上传文件
你的上传。。。
文件名
文件类型
文件大小(KB)
看法
我正在尝试更改此记录:
$sql=“从文件中选择*”代码>
到
$sql=“从userId='$\u会话[userId]'所在的文件中选择文件、类型、大小”代码>
但是我仍然没有得到正确的结果。有人能帮忙吗?这行代码的问题似乎在于如何包含$\u会话变量。在userId
周围应该有引号,比如$\u会话['userId']
或{$\u会话['userId']}
更重要的是,您应该避免在MySQL查询中直接输入变量。我建议使用或代替MySQL,并查看准备好的语句(例如,或)。MySQL已被弃用,请改用mysqli。您能具体说明您的意思吗?