开发者

problem in php when retrieving data from database

I have one problem regardin开发者_运维问答g retriving data from database. I have created one database in userrecord and its table name is tbl_user. I am trying to display the user information when they log in the system. i.e view logged user profile. The code is as follows:

<?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>

The code echo $row[' '] is not displaying the record from database.


try:

<?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);
?>


and its table name is tbl_user

And your SQL was table_user?

Anyway, I didn't see others mistake with your code, just that. If it was a typo, try to debug your connection, and give us the error message...


no need for this @ symbol:

$result=@mysql_query($sql,$connection);

Correction:

$result=mysql_query($sql,$connection);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜