learner0001 Posted September 8, 2014 Share Posted September 8, 2014 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> Quote Link to comment https://forums.phpfreaks.com/topic/290921-how-to-retreive-specific-values-from-database-to-display-on-webpage/ Share on other sites More sharing options...
Richard_Grant Posted September 8, 2014 Share Posted September 8, 2014 (edited) <?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 September 8, 2014 by Richard_Grant Quote Link to comment https://forums.phpfreaks.com/topic/290921-how-to-retreive-specific-values-from-database-to-display-on-webpage/#findComment-1490312 Share on other sites More sharing options...
cyberRobot Posted September 8, 2014 Share Posted September 8, 2014 Get the Values you need by running the php above... 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 Quote Link to comment https://forums.phpfreaks.com/topic/290921-how-to-retreive-specific-values-from-database-to-display-on-webpage/#findComment-1490316 Share on other sites More sharing options...
Richard_Grant Posted September 8, 2014 Share Posted September 8, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/290921-how-to-retreive-specific-values-from-database-to-display-on-webpage/#findComment-1490317 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.