Page 1 of 1

User profile broblem

Posted: Mon Jul 02, 2012 1:31 pm
by rafail123
It doesnt work correctly for me these scripts! I dont know what is the problem. I copiyed all the files exactly as they are. And when i go in user_list.php page i get nothing. Only a blank page! If i write something like echo "test" in code of user_list.php i can see it. But not the links! What may be the problem? I think something is wrong with user.inc.php file. Any ideas??

These are my files:

user_list.php:
<?php
 
error_reporting(E_ALL ^ E_WARNING) ;
 
include ('/core/init.inc.php') ;
 
 
?>
 
 
<html>
<head>
<title>Registered Users!</title>
</head>
<body>
<div>
<?php
 
foreach (fetch_users() as $user)  {
 
?>
<p>
        <a href="profile.php?uid=<?php echo $user['id'] ?>" ><?php echo $user ['username'] ; ?></a>
 
</p>
<?php
}
?>
<div>
</body>
</html>
init.inc.php:
<?php
error_reporting (E_ALL ^ E_NOTICE) ;
session_start () ;
 

	$c_username = "user";
	$c_password = "pass";
	$c_host = "localhost";
	$c_database = "dbname";

	$connection = mysql_connect($c_host, $c_username, $c_password)
	or die ("It seems this site's database isn't responding." );

	mysql_select_db($c_database, $connection)
	or die ("It seems this site's database isn't responding."  . mysql_error());

 
$path = dirname (__FILE__);
 
include ('{$path}/inc/user.inc.php') ;
 
$_SESSION ['uid']= 1 ;
 
?>
user.inc.php
<?php
// fetches all of the users from the table!
function fetch_users() {
        $result = mysql_query ("SELECT `user_id` AS `id`, `user_username` AS `username` FROM `users`") ;
        $users = array () ;
 
while (($row = mysql_fetch_assoc($result)) !== false) {
        $users [] = $row ;
 
        }      
          return $users ;
}
 
function fetch_user_info ($uid) {
        $uid = (int)$uid;
        $sql = "SELECT
                              `user_username` AS `username`,
                              `user_firstname` AS `firsntame`,
                              `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) ;
}
//updates the current users proifle
function set_profile_info ($email, $about, $location){
$email          = mysql_real_escape_string (htmlentities($email)) ;
$about          = mysql_real_escape_string (nl2br(htmlentities($about))).
$location       = mysql_real_escape_string ($location) ;
 
$sql = "UPDATE `users` SET
                                `user_email` = '{$email}' ,
                                `user_about` = '{$about}',
                                `user_location` = '{$location}'
                WHERE `user_id` = {$_SESSION ['uid']}" ;
               
                mysql_query ($query) ;
 
 
}
?>
and the profile.php and edit_profile.php

Re: User profile broblem

Posted: Mon Jul 02, 2012 2:49 pm
by Temor
This line needs to have Quotes, not apostrophes.
This will try to include {$path}/inc/user.inc.php. And {$path} is not an actual path, it's a variable name.
include ('{$path}/inc/user.inc.php') ;
This will print the value of the variable, instead of the variable name.
include ("{$path}/inc/user.inc.php") ;

You should have gotten an error.

Re: User profile broblem

Posted: Mon Jul 02, 2012 3:25 pm
by rafail123
Thanks a lot! It finally worked! :D I will keep it in mind for the quotes!!