Jump to content

how to retreive specific values from database to display on webpage


learner0001

Recommended Posts

i have a register and login page where the users can perform register and login task and their detail gets saved in the database. my requirement is that when the user enters his/her account, they should be redirected to their profile page, where they can view all their profile details. Till now i have been able to make the user login and dislay a part of their profile page, for this purpose the code that i am using is

 

<code>

<?php
include('retailer_session.php');
?>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Welcome to your homepage</title>
        <meta name="viewport" content="width=device-width", initial-scale=1.0">
        <link href="css/bootstrap.min.css" rel="stylesheet" />
        <link href="css/styles.css" rel="stylesheet" />
        <link href="css/carousel.css" rel="stylesheet">
</head>
<body>
<div id="profile">
    <div class="navbar navbar-inverse navbar-static-top">
        <div class="container">
            <a href="#" class = "navbar-brand"> <id="welcome">Welcome : <i><?php echo $login_session; ?></i> </a>
                <button class = "navbar-toggle" data-toggle = "collapse" data-target = ".navHeaderCollapse">
                    <span class = "icon-bar"> </span>
                    <span class = "icon-bar"> </span>
                    <span class = "icon-bar"> </span>
                </button>
            <div class="collapse navbar-collapse navHeaderCollapse">
                <ul class = "nav navbar-nav navbar-right">
                    <li class ="active"> <a href="admin_profile.php">Home</a></li>
                    <li> <a href="retailer_logout.php"><id="logout">Log Out</a></li>
                </ul>
            </div>
        </div>     
    </div>
</div>
</body>
</html>
 
Apart from this i want a listing where the user can view their data and edit their details as it is done on many websites. can anyone please help me with the code

</code>

Link to comment
Share on other sites

<?php

$conn = mysql_connect("localhost", "mysql_user", "mysql_password");

if (!$conn) {
    echo "Unable to connect to DB: " . mysql_error();
    exit;
}

if (!mysql_select_db("mydbname")) {
    echo "Unable to select mydbname: " . mysql_error();
    exit;
}

$sql = "SELECT id as userid, fullname, userstatus
        FROM   sometable
        WHERE  userstatus = 1";

$result = mysql_query($sql);

if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}

// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
//       then create $userid, $fullname, and $userstatus
while ($row = mysql_fetch_assoc($result)) {
    echo $row["userid"];
    echo $row["fullname"];
    echo $row["userstatus"];
}

mysql_free_result($result);

?>

Get the Values you need by running the php above, then store them in a session. and then change your .html file to a .php filetype.

and then you can put <?PHP echo $_SESSION['value']; ?> where ever you want.

Edited by Richard_Grant
Link to comment
Share on other sites

Just be aware that mysql_* functions have been deprecated. If you're not doing so already, you'll need to switch to PDO or MySQLi at some point. More information can be found here:

http://php.net/manual/en/mysqlinfo.api.choosing.php

I agree, i use prepared statements in mysqli, mysql is depreciated. Good point out.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.