Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have tried numerous combinations of code to try and display my client data to them on their own profile page once they log in.

This is my first time designing a website and i have never worked with MySQL before but i have developed a quick understanding of how it all works.

I understand that i need to create sessions to 'store' their information when they log in then i can display it as i wish ?

Does anyone have any code that i could use?

My SQL info:

  • db: taxretur_login
  • table: members

aspects i would like to show:

  • name
  • email
  • username

Thanks. Stan.

UPDATE:

This code works and pulls all my table info accross to a users page but i only want data unique to that paticular user:

<?php
$dbhost = 'localhost';
$dbuser = '';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT id_user, email, 
           name, username
    FROM members';

mysql_select_db('taxretur_login');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_assoc($retval))
{
echo "User ID :{$row['id_user']}  <br> ".
     "Email: {$row['email']} <br> ".
     "Name: {$row['name']} <br> ".
     "Username : {$row['username']} <br> ".
     "--------------------------------<br>";
}  
echo "Fetched data successfully
";
mysql_close($conn);
?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
282 views
Welcome To Ask or Share your Answers For Others

1 Answer

Create members table in your database

CREATE TABLE `members` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` char(20) NOT NULL,
  `name` char(30) NOT NULL,
  `email` char(40) NOT NULL,
  `pass` char(20) NOT NULL,
  PRIMARY KEY (`id`)
);

Add an user into table members

INSERT INTO `members` VALUES ('1', 'user1', 'mr. x', 'email@domain.com', '123');

Just change the variable as your mysql user in page connection.php

connection.php

<?php
$mysql_host = "localhost";
$mysql_user = "root";
$mysql_pass = "";
$mysl_database = "taxretur_login";

$conn = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
mysql_select_db($mysl_database, $conn);
?>

login.php

<?php
include("connection.php");

if(isset($_POST["submit"])) {
    $username = $_POST["username"];
    $pass = $_POST["pass"];

    $sql = "SELECT * FROM members 
            WHERE username='$username' AND pass='$pass'";
    $result = mysql_query($sql);
    $numRows = mysql_num_rows($result);
    if($numRows==1) {
        session_start();
        $_SESSION["username"] = $username;
        header("Location: ./profile.php");
    } else {
        echo "Invalid Login Information";   
    }
}
?>

<form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
<table>
<tr><td>User Name</td><td><input type="text" name="username" /></td></tr>
<tr><td>Password</td><td><input type="password" name="pass" /></td></tr>
<tr><td></td><td><input type="submit" name="submit" value="Login" /></td></tr>
</table>
</form>

profile.php

<?php
session_start();
include("connection.php");

$username = $_SESSION["username"];

$sql = "SELECT * FROM members WHERE username='$username'";
$result = mysql_query($sql);

if($row = mysql_fetch_array($result)) {
    $username = $row["username"];
    $name = $row["name"];
    $email = $row["email"];

    echo "
    <table>
        <tr><td>User Name</td><td> : </td><td>$username</td></tr>
        <tr><td>Name</td><td> : </td><td>$name</td></tr>
        <tr><td>Email</td><td> : </td><td>$email</td></tr>
    </table>
    ";
}
?>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...