Click here to Skip to main content
15,898,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to create a user profile page,and what i want right is how to echo the users information from the database to display in a profile page once they login from the login page,but the problem is that will echo The user ID is not defined.ilease i need help anyone can help me fix my code am new to php and sql.

What I have tried:

profile.php

PHP
<?php
include('db.php');
?>
<!DOCTYPE html">
<html>
    <head>
        <title>Profile of an user</title>
    </head>
    <body>

        <div class="content">
<?php
//We check if the users ID is defined
if(isset($_GET['id']))
{
        $id = intval($_GET['id']);
        //We check if the user exists
        $sql = mysql_query('SELECT fst, las, uid, pass,sts,ocp FROM users WHERE id="'.$id.'"');
        if(mysql_num_rows($sql)>0)
        {
                $res = mysql_fetch_array($sql);
                //We display the user datas
?>
This is the profile of "<?php echo htmlentities($res['fst']); ?>" :
<table style="width:500px;">
        <tr>

        <td class="left"><h1><?php echo htmlentities($res['fst']); ?></h1>
        Email: <?php echo htmlentities($dnn['las']); ?><br />
        This user joined the website on <?php echo htmlentities($res['uid']); ?></td>
    </tr>
</table>
<?php
        }
        else
        {
                echo 'This user dont exists.';
        }
}
else
{
        echo 'The user ID is not defined.';
}
?>
                </div>
                 </body>
</html>


login.php

PHP
<?php
include 'db.php';

$uid = $_POST['uid'];
$pass = $_POST['pass'];



$sql = "SELECT * FROM users WHERE uid='$uid' AND pass='$pass'";
$result = mysqli_query($conn,$sql);

if($row = mysqli_fetch_assoc($result)){
   header("Location: profile.php");
   
}else{
     echo "invalid username or password";
}
?>
Posted
Updated 25-May-17 21:58pm
v2
Comments

1 solution

I dont know PHP but It seems you are not able to set id in profile.php

You can find id from login.php, Once user logged In successfully you have to pass id to profile.php then you can able to get profile detail of a particular user.

You should pass data like this from login.php

<?php
include 'db.php';
 
$uid = $_POST['uid'];
$pass = $_POST['pass'];
 

$sql = "SELECT * FROM users WHERE uid='$uid' AND pass='$pass'";
$result = mysqli_query($conn,$sql);
 
if($row = mysqli_fetch_assoc($result)){
   header("Location: profile.php?id=$rows[id]");
   
}else{
     echo "invalid username or password";
}
?>



I hope this is clear to you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900