well the point is that im not getting any information in edit-profie.php about user i only get html box without echo in it <label for="username">Username</label> <input type="text" name="username" id="username" value="<?php echo $user_info ['username']; ?>" /> </div><div> the box is empty but its supposed to see a $user info Username $user_info = fetch_user_info($_SESSION['Username']); the session is wrong, cant detect im logged in. but otherwise if im logged out i cant see the page
Sounds like you aren't even starting the session. Add session_start(); to the very top of your script right after your first <?php tag. If that does nothing post your two inc.php files I believe it is init.inc.php and user.inc.php I'm not sure as I've never followed this tutorial.
function fetch_users (){ $result = mysql_query('SELECT `uid` AS `id`, `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 `username` AS `username`, `grad` AS `grad`, `drzava` AS `drzava`, `fan` AS `fan`, `Website` AS `Website` FROM users WHERE `uid` = '$uid'";
mysql_query("UPDATE `users` SET `username` = `$username`, `grad` = `$grad`, `drzava` = `$drzava`,`fan` = `$fan`, `website` = `$website` WHERE `uid`=`$uid`"); }
?>[/syntax]
init.inc.php
[syntax=php]<?php
session_start();
$dbhost = "mysql14.000webhost.com"; // this will ususally be 'localhost', but can sometimes differ $dbname = "myname"; // the name of the database that you are going to use for this project $dbuser = "myuser"; // the username that you created, or were given, to access your database $dbpass = "mypass"; // the password that you created, or were given, to access your database
mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error()); mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());
The fetch_user_info function is gathering data from the user using their uid. Not their username, as your previously posted. Replace $_SESSION['Username'] with whatever their session uid is stored as.
I'm not sure why you are setting their $_SESSION['uid'] to 1 in init.inc.php either as each user should have their own unique uid
well i removed $_SESSION ['uid'] = 1; from init user.inc.php is getting a new error because i inserted include('core/init.inc.php'); maybe i shouldnt do that? Fatal error: Cannot redeclare fetch_users() (previously declared in public_html/core/inc/user.inc.php:7) in /public_html/core/inc/user.inc.php on line 17
but cant really understand with that should i change $_SESSION['Username'] i inserted $_SESSION['uid'] but its not working
All files already call each other. You can not call a file with functions twice because a function can not be redeclared, hence the error you are getting. You must remove that include you added to remove the error.
Are you setting $_SESSION['uid'] when you log in your users? If not, you need to.
I really see nothing wrong with your code other than what appeared to be those details. I can only suggest if you do not find the source of your error in the question above, that you wait for further assistance
Im setting [syntax=php]<?php if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) {[/syntax] When they are logged in they can see the page.
That does not mean you are setting $_SESSION['uid'] Wherever you are processing the user login, if you do not see yourself setting $_SESSION['uid'] You need to.
echo "<h1><center>Success</center></h1>"; echo "<p><center>We are now redirecting you to the member area.</center></p>"; echo "<meta http-equiv='refresh' content='=2;user.php' />"; } else { echo "<h1>Error</h1>"; echo "<p>Sorry, your account could not be found. Please <a href=\"user.php\">click here to try again</a>.</p>"; } } else { ?> <?php } ?> [/syntax]
Whatever column in the database you are using to store the user's uid (I believe it is just called uid) set the $_SESSION['uid'] with it. [syntax=php] if(mysql_num_rows($checklogin) == 1) { $row = mysql_fetch_array($checklogin);
echo "<h1><center>Success</center></h1>"; echo "<p><center>We are now redirecting you to the member area.</center></p>"; echo "<meta http-equiv='refresh' content='=2;user.php' />"; } [/syntax] The above is where you are setting your $_SESSION variables. Add a new line above $_SESSION['Username'] with the following: [syntax=php]$_SESSION['uid'] = $row['uid'];[/syntax] If your column in the database is not uid change $row['uid'] to $row['your column name']
Once you have updated it, logout and log back in to check for errors and so that your $_SESSION['uid'] will be set
still the same nothing happens session in user.inc.php is $uid = ($_SESSION['uid'] = $row['uid']); session in edit.profile.php is $user_info = fetch_user_info ($_SESSION['uid'] = $row['uid']); session in login is of course $_SESSION['uid'] = $row['uid'];
when i put in edit.profile.php $user_info = fetch_user_info $_SESSION['uid']; i get error Parse error: syntax error, unexpected T_VARIABLE in public_html/edit_profile.php on line 39 but when i put $user_info = fetch_user_info( $_SESSION['uid']); its still the same
You are supposed to use $user_info = fetch_user_info($_SESSION['uid']); I'm not sure if that whitespace you added matters. It shouldn't.
Looking back at what Temor said, I believe I see what they were talking about. [syntax=php] if (empty($errors)){ $grad = htmlentities($_POST['grad']); $drzava = htmlentities($_POST['drzava']); $fan = htmlentities($_POST['fan']); $website = htmlentities($_POST['website']);
if (isset($errors) ==false){ echo 'Click update to edit your profile.'; }else if (empty($errors)){ echo 'Your profile has been updated!'; }else{ echo '<ul><li>'. implode('</li><li>'. $errors). '</li></ul>'; }
echo "<h1><center>Success</center></h1>"; echo "<p><center>We are now redirecting you to the member area.</center></p>"; echo "<meta http-equiv='refresh' content='=2;user.php' />"; } else { echo "<h1>Error</h1>"; echo "<p>Sorry, your account could not be found. Please <a href=\"user.php\">click here to try again</a>.</p>"; } } else { ?> <?php } ?>[/syntax]