Jump to content

pull from database on profile page


lee2010

Recommended Posts

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>

 

 

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

 

 

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.