lee2010 Posted November 22, 2010 Share Posted November 22, 2010 hi all, i have a profile page which is a form that asks users to enter there personal details such as name, location, mobile number etc and saves this info with a mysql database, however when you return to the edit profile page the fields are blank and i want them to pull the details the user has entered (if any) and display it, so if a user entered there name as Lee, then returned to the edit profile page there name field would show lee instead of being empty. heres my profiles page code, any help would be great <?PHP session_start(); if (!(isset($_SESSION['username']) && $_SESSION['username'] != '')) { header ("Location: login.php"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!-- Author: Reality Software Website: http://www.realitysoftware.ca Note: This is a free template released under the Creative Commons Attribution 3.0 license, which means you can use it in any way you want provided you keep the link to the author intact. --> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <link href="style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> .auto-style2 { font-size: 25px; } </style> </head> <body> <div id="container"> <!-- header --> <div id="header"> <div id="logo"><a href="#"><span class="orange">SouthWest</span> LAN's</a></div> <div id="menu"> <ul> <li><a href="index.php">home</a></li> <li><a href="register.php">Register</a></li> <li><a href="account.php">My Account</a></li> <li><a href="forum.php">Forums</a></li> <li><a href="faq.php">FAQ</a></li> </ul> </div> </div> <!--end header --> <!-- main --> <div id="main"> <div id="content"> <div id="head_image"> <div id="slogan"><strong><span class="auto-style2">Organising LAN Parties in the SouthWest</span></strong><br /></div> <div id="under_slogan_text"></div> </div> <div id="text"> <h1>Edit Profile</h1> <br /> <form name="register" method="post" action="process_p.php"> <table border="0" width="225" align="center"> <tr> <td width="219" bgcolor="#999999"> <p align="center"><font color="white"><span style="font-size:12pt;">Please fill out as much as possible</span></font></p> </td> </tr> <tr> <td width="219"> <table border="0" width="282" align="center"> <tr> <td width="116"><span style="font-size:10pt;">Username: </span></td> <td width="156"><?php echo $_SESSION['username']; ?></td> </tr> <tr> <td width="116"><span style="font-size:10pt;">Email: </span></td> <td width="156"><input type="text" name="email" maxlength="30"></td> </tr> <tr> <td width="116"><span style="font-size:10pt;">Real Name: </span></td> <td width="156"><input type="text" name="real_name"></td> </tr> <tr> <td width="116"><span style="font-size:10pt;">Location: </span></td> <td width="156"><input type="text" name="location"></td> </tr> <tr> <td width="116"><span style="font-size:10pt;">Mobile Number: </span></td> <td width="156"><input type="text" name="mobile_number"></td> </tr> <tr> <td width="116"><span style="font-size:10pt;">Instant Messager: </span></td> <td width="156"><input type="text" name="instant_messaging"></td> </tr> <tr> <td width="116"> </td> <td width="156"> <p align="right"><input type="submit" name="update" value="Update Profile"></p> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/219480-pull-from-database-on-profile-page/ Share on other sites More sharing options...
Pikachu2000 Posted November 22, 2010 Share Posted November 22, 2010 When the user logs in, save their user id (which should probably be the PK ID from their record in the database) as a $_SESSION var, then use that value to run a SELECT query, and those results to populate the value= attributes of the form fields. Quote Link to comment https://forums.phpfreaks.com/topic/219480-pull-from-database-on-profile-page/#findComment-1137998 Share on other sites More sharing options...
lee2010 Posted November 22, 2010 Author Share Posted November 22, 2010 thanks for your reply, could i not use there username instead of a user id, have something like: $result = mysql_query("SELECT * FROM users WHERE `username` = '".$_SESSION['username']."' LIMIT 1"; then also im not sure how to display this within my table, would this line work inside the forms value field <? echo $rows['real_name']; ?> so it would be: <td width="116"><span style="font-size:10pt;">Real Name: </span></td> <td width="156"><input type="text" name="real_name" value="<? echo $rows['real_name']; ?>"></td> woul that work or would it need something else? Quote Link to comment https://forums.phpfreaks.com/topic/219480-pull-from-database-on-profile-page/#findComment-1138007 Share on other sites More sharing options...
trochia Posted November 22, 2010 Share Posted November 22, 2010 The first step is along the lines of: // Welcome the user (by name if they are logged in). echo '<h1>Welcome'; if (isset($_SESSION['first_name'])) { echo ", {$_SESSION['first_name']}!"; } As Pikachu2000 mentions... You might would like to research 'sessions & user tracking' Jim Quote Link to comment https://forums.phpfreaks.com/topic/219480-pull-from-database-on-profile-page/#findComment-1138008 Share on other sites More sharing options...
Pikachu2000 Posted November 22, 2010 Share Posted November 22, 2010 You could use the username as the search field, but I believe a query against a primary key, integer index field will be faster, assuming the table has such a field. Quote Link to comment https://forums.phpfreaks.com/topic/219480-pull-from-database-on-profile-page/#findComment-1138011 Share on other sites More sharing options...
lee2010 Posted November 22, 2010 Author Share Posted November 22, 2010 users are assigned a user_id which is auto_incremented and is the primary key within my database however i would prefer to use the session username rather than there user_id, also speed isn't as issue at the moment so if i wanted to use there username as the search variable was i correct in my above post on how to write the table showing the data? Quote Link to comment https://forums.phpfreaks.com/topic/219480-pull-from-database-on-profile-page/#findComment-1138014 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.