User Profile System - Info for edit_profile not showing :(i
Posted: Tue Jan 17, 2012 8:45 am
Sorry to give you two posts in 1 day, but I am banging my head against the wall trying to figure out what I've missed, and after re-watching the videos numerous times, I just can't find it.
I'm trying to do the Member Profile tutorials and I have everything working thus far, the user list works great, the profile pages work great, but when I get to the edit profile page, it only displays the form, but there's no data in it.
I've dropped the page to bare minimum and tried to just echo out a user name to see if it would at least display that, and it doesn't. I check the protected page to make sure I'm still logged in as a user and I am. So, I'm not sure why it won't recognize the user session on the edit profile page. Anyhow, here's my code - sorry that it's mixed in with my other page code, but that shouldn't be affecting it as it's the same code on all the other pages that work just fine.
Here it is -
init.inc.php
I'm trying to do the Member Profile tutorials and I have everything working thus far, the user list works great, the profile pages work great, but when I get to the edit profile page, it only displays the form, but there's no data in it.
I've dropped the page to bare minimum and tried to just echo out a user name to see if it would at least display that, and it doesn't. I check the protected page to make sure I'm still logged in as a user and I am. So, I'm not sure why it won't recognize the user session on the edit profile page. Anyhow, here's my code - sorry that it's mixed in with my other page code, but that shouldn't be affecting it as it's the same code on all the other pages that work just fine.
Here it is -
init.inc.php
<?php session_start(); $exceptions = array('register', 'login'); $page = substr(end(explode('/', $_SERVER['SCRIPT_NAME'])), 0, -4); mysql_connect('localhost', 'root', 'root'); mysql_select_db('user_system'); $path = dirname(__FILE__); include("{$path}/inc/user.inc.php"); //added variable in profile tutorial $_SESSION['uid'] = 1; //end added variable if (isset($_COOKIE['username'], $_COOKIE['password']) && isset($_SESSION['username']) === false){ if (valid_credentials($_COOKIE['username'], $_COOKIE['password'])){ $_SESSION['username'] = htmlentities($_COOKIE['username']); setcookie('username', $_COOKIE['username'], time() + 604800); setcookie('password', $_COOKIE['password'], time() + 604800); } } if (in_array($page, $exceptions) === false){ if (isset($_SESSION['username']) === false){ header('Location: login.php'); die(); } } ?>user.inc.php
<?php //checks if the given username exists in the database function user_exists($user){ $user = mysql_real_escape_string($user); $total = mysql_query("SElECT COUNT(`user_id`) FROM `users` WHERE `user_name` = '{$user}'"); return (mysql_result($total, 0) == '1') ? true : false; } //checks if the given username and password combination is valid function valid_credentials($user, $pass){ $user = mysql_real_escape_string($user); $pass = mysql_real_escape_string($pass); $total = mysql_query("SElECT COUNT(`user_id`) FROM `users` WHERE `user_name` = '{$user}' AND `user_password` = '{$pass}'"); return (mysql_result($total, 0) == '1') ? true : false; } //adds a user to the database function add_user($user, $pass){ $user = mysql_real_escape_string(htmlentities($user)); $pass = sha1($pass); mysql_query("INSERT INTO `users` (`user_name`, `user_password`) VALUES ('{$user}', '{$pass}')"); } //fetches all of the users from the table. function fetch_users(){ $result = mysql_query('SELECT `user_id` AS `id`, `user_name` AS `username` FROM `users` '); $users = array(); while (($row = mysql_fetch_assoc($result)) !== false){ $users[] = $row; } return $users; } //fetches profile information for the given user function fetch_user_info($uid){ $uid = (int)$uid; $sql = "SELECT `user_name` AS `username`, `user_firstname` AS `firstname`, `user_lastname` AS 'lastname', `user_email` AS `email`, `user_about` AS `about`, `user_location` AS `location`, `user_gender` AS `gender` FROM `users` WHERE `user_id` = {$uid}"; $result = mysql_query($sql); return mysql_fetch_assoc($result); } ?>user_list.php
<?php include('core/init.inc.php'); ?> <!DOCTYPE html> <html lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>informapet - Complete Resource for Pet Adoption</title> <link rel="stylesheet" href="css/style.css" type="text/css"> <link rel="stylesheet" href="css/cupertino/jquery-ui-1.8.17.custom.css" type="text/css" /> <script type="text/javascript" src="js/main.js"></script> <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script> <script type="text/javascript" src="js/jquery-ui-1.8.17.custom.min.js"></script> <!--[if lt IE 9]> <script type="text/javascript"> document.createElement("nav"); document.createElement("header"); document.createElement("footer"); document.createElement("section"); document.createElement("aside"); document.createElement("article"); </script> <![endif]--> <link rel="stylesheet" href="css/slide.css" type="text/css" media="screen" /> <!-- PNG FIX for IE6 --> <!-- http://24ways.org/2007/supersleight-tra ... png-in-ie6 --> <!--[if lte IE 6]> <script type="text/javascript" src="js/pngfix/supersleight-min.js"></script> <![endif]--> <!-- Sliding effect --> <script src="js/slide.js" type="text/javascript"></script> </head> <body> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path.= "/includes/logo.php"; include_once ($path); ?> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path.= "/includes/loginout.php"; include_once ($path); ?> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path.= "/includes/header.php"; include_once ($path); ?> <section id="posts"> <article class="post"> <header> <h2>User List</h2> </header> <section> <?php foreach (fetch_users() as $user){ ?> <p> <a href="profile.php?uid=<?php echo $user['id']; ?>"><?php echo $user['username']; ?></a> </p> <?php } ?> </section> </article> </section> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path.= "/includes/sidebar.php"; include_once ($path); ?> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path.= "/includes/footer.php"; include_once ($path); ?> </body> </html>profile.php
<?php include('core/init.inc.php'); $user_info = fetch_user_info($_GET['uid']); ?> <!DOCTYPE html> <html lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>informapet - <?php echo $user_info['username']; ?>'s profile</title> <link rel="stylesheet" href="css/style.css" type="text/css"> <link rel="stylesheet" href="css/contact.css" type="text/css"> <link rel="stylesheet" href="css/cupertino/jquery-ui-1.8.17.custom.css" type="text/css" /> <script type="text/javascript" src="js/main.js"></script> <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script> <script type="text/javascript" src="js/jquery-ui-1.8.17.custom.min.js"></script> <!--[if lt IE 9]> <script type="text/javascript"> document.createElement("nav"); document.createElement("header"); document.createElement("footer"); document.createElement("section"); document.createElement("aside"); document.createElement("article"); </script> <![endif]--> <link rel="stylesheet" href="css/slide.css" type="text/css" media="screen" /> <!-- PNG FIX for IE6 --> <!-- http://24ways.org/2007/supersleight-tra ... png-in-ie6 --> <!--[if lte IE 6]> <script type="text/javascript" src="js/pngfix/supersleight-min.js"></script> <![endif]--> <!-- Sliding effect --> <script src="js/slide.js" type="text/javascript"></script> </head> <body> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path.= "/includes/logo.php"; include_once ($path); ?> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path.= "/includes/loginout.php"; include_once ($path); ?> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path.= "/includes/header.php"; include_once ($path); ?> <section id="posts"> <article class="post"> <header> <h2>Profiles</h2> </header> <section> <?php if ($user_info === false){ echo 'That user does not exist.'; }else{ ?> <h1><?php echo $user_info['firstname']; ?> <?php echo $user_info['lastname']; ?></h1> <p>Username: <?php echo $user_info['username']; ?> </p> <p>Gender: <?php echo ($user_info['gender'] == 1) ? 'Female' : 'Male'; ?></p> <p>Email: <?php echo $user_info['email']; ?></p> <p>Location: <?php echo $user_info['location']; ?></p> <p><?php echo $user_info['about']; ?></p> <?php } ?> </section> </article> </section> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path.= "/includes/sidebar.php"; include_once ($path); ?> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path.= "/includes/footer.php"; include_once ($path); ?> </body> </html>edit_profile.php
<?php include('core/init.inc.php'); $user_info = fetch_user_info($_SESSION['uid']); ?> <!DOCTYPE html> <html lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>informapet - <?php echo $user_info['username']; ?>'s profile</title> <link rel="stylesheet" href="css/style.css" type="text/css"> <link rel="stylesheet" href="css/contact.css" type="text/css"> <link rel="stylesheet" href="css/cupertino/jquery-ui-1.8.17.custom.css" type="text/css" /> <script type="text/javascript" src="js/main.js"></script> <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script> <script type="text/javascript" src="js/jquery-ui-1.8.17.custom.min.js"></script> <!--[if lt IE 9]> <script type="text/javascript"> document.createElement("nav"); document.createElement("header"); document.createElement("footer"); document.createElement("section"); document.createElement("aside"); document.createElement("article"); </script> <![endif]--> <link rel="stylesheet" href="css/slide.css" type="text/css" media="screen" /> <!-- PNG FIX for IE6 --> <!-- http://24ways.org/2007/supersleight-tra ... png-in-ie6 --> <!--[if lte IE 6]> <script type="text/javascript" src="js/pngfix/supersleight-min.js"></script> <![endif]--> <!-- Sliding effect --> <script src="js/slide.js" type="text/javascript"></script> </head> <body> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path.= "/includes/logo.php"; include_once ($path); ?> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path.= "/includes/loginout.php"; include_once ($path); ?> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path.= "/includes/header.php"; include_once ($path); ?> <section id="posts"> <article class="post"> <header> <h2>Edit Profile</h2> </header> <form action="" method="post"> <fieldset id="personal_information"> <legend>Edit Profile</legend> <ol> <li> <label for="email">Email:</label> <input type="text" name="email" id="email" value="<?php echo $user_info['email']; ?>"/> </li> <li> <label for="email">Location:</label> <input type="text" name="location" id="location" value="<?php echo $user_info['location']; ?>"/> </li> <li> <label for="email">About Me:</label> <textarea name="about" rows="14" cols="50"><?php echo $user_info['about']; ?></textarea> </li> <li> <input type="submit" value="Update" /> </li> </ol> </fieldset> </form> </article> </section> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path.= "/includes/sidebar.php"; include_once ($path); ?> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path.= "/includes/footer.php"; include_once ($path); ?> </body> </html>Again, I'm eternally grateful for all your help thus far and any help you can provide on this issue. Desperately trying to learn how to create a site from the ground up by myself and without your tutorials, I don't know where I'd be.