gpt4 book ai didi

php - 从数据库中检索数据时php中的问题

转载 作者:搜寻专家 更新时间:2023-10-30 23:20:21 26 4
gpt4 key购买 nike

我有一个关于从数据库中检索数据的问题。我在userrecord 中创建了一个数据库,它的表名是tbl_user。我试图在用户登录系统时显示用户信息。即查看记录的用户配置文件。代码如下:

<?php
include("auth_user.inc.php"); // authrization page
$uname=$_SESSION['user']; // logged user name
$connection=mysql_connect("localhost","root"," ");
mysql_select_db("userrecord",$connection);
$sql=("select * from table_user where uname ='$uname'");
$result=@mysql_query($sql,$connection);
$row=mysql_fetch_array($result);
?>
<html>
<head>
<title>User Account</title>
</head>
<body bgcolor="#33CCFF">
<br>Your Details Information Is Shown Below:<br><br>
First Name:<?php echo $row['fname'];?><br>
Last Name:<?php echo $row['lname'];?><br>
Address:<?php echo $row['address'];?><br>
E-Mail:<?php echo $row['email'];?><br>
Gender:<?php echo $row['fname'];?><br>
User Name:<?php echo $row['uname'];?><br>
</body>
</html>

代码 echo $row[' '] 没有显示数据库中的记录。

最佳答案

尝试:

<?php
include("auth_user.inc.php"); // authrization page
$uname = $_SESSION['user']; // logged user name
$connection = mysql_connect("localhost","root"," ") or die('Could not connect to database: '.mysql_error());
mysql_select_db("userrecord",$connection) or die('Could select database: '.mysql_error());
$sql = "select * from table_user where uname ='$uname'";
$result = mysql_query($sql) or die ('Mysql error: '.mysql_error.' - '.mysql_errno());
$row = mysql_fetch_array($result);
?>

关于php - 从数据库中检索数据时php中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7440267/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com