cannot edit profile
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
Re: cannot edit profile
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
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
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: cannot edit profile
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.
<?php while(!$succeed = try()); ?>
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
Re: cannot edit profile
Yes i inserted that now, it was empty in the bottom of edit.profile.php and user.inc.php, but still thats not the main problem
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
Re: cannot edit profile
User.inc.php
<?php session_start(); 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'"; $result = mysql_query($sql); return mysql_fetch_assoc($result); } function set_profile_info($username, $grad, $drzava, $fan, $website){ $username = mysql_real_escape_string(htmlentities($username)); $grad = mysql_real_escape_string(htmlentities($grad)); $drzava = mysql_real_escape_string(htmlentities($drzava)); $fan = mysql_real_escape_string(htmlentities($fan)); $website = mysql_real_escape_string(htmlentities($website)); $uid = $_SESSION['uid']; mysql_query("UPDATE `users` SET `username` = `$username`, `grad` = `$grad`, `drzava` = `$drzava`,`fan` = `$fan`, `website` = `$website` WHERE `uid`=`$uid`"); } ?>init.inc.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()); $path = dirname (__FILE__); include "$path/inc/user.inc.php"; $_SESSION ['uid'] = 1; ?>
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: cannot edit profile
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
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
<?php while(!$succeed = try()); ?>
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
Re: cannot edit profile
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
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
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: cannot edit profile
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
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
<?php while(!$succeed = try()); ?>
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
Re: cannot edit profile
Im setting
<?php if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) {When they are logged in they can see the page.
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: cannot edit profile
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.
<?php while(!$succeed = try()); ?>
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
Re: cannot edit profile
i can edit session LoggedIn and put session uid then?
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: cannot edit profile
You can set many session variables. No need to edit any.
If you need help, post the file that you process your login.
If you need help, post the file that you process your login.
<?php while(!$succeed = try()); ?>
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
Re: cannot edit profile
<?php if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) { ?> <?php } elseif(!empty($_POST['username']) && !empty($_POST['password'])) { $username = mysql_real_escape_string($_POST['username']); $password = md5(mysql_real_escape_string($_POST['password'])); $checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'"); if(mysql_num_rows($checklogin) == 1) { $row = mysql_fetch_array($checklogin); $_SESSION['Username'] = $username; $_SESSION['LoggedIn'] = 1; 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 } ?>
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: cannot edit profile
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.
Once you have updated it, logout and log back in to check for errors and so that your $_SESSION['uid'] will be set
if(mysql_num_rows($checklogin) == 1) { $row = mysql_fetch_array($checklogin); $_SESSION['Username'] = $username; $_SESSION['LoggedIn'] = 1; 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' />"; }The above is where you are setting your $_SESSION variables. Add a new line above $_SESSION['Username'] with the following:
$_SESSION['uid'] = $row['uid'];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
<?php while(!$succeed = try()); ?>
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
Re: cannot edit profile
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'];
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'];
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: cannot edit profile
You only need the = $row['uid'] in the login process. Change those (user.inc.php and edit_profile.php) back to just $_SESSION['uid']
<?php while(!$succeed = try()); ?>
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
Re: cannot edit profile
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
but when i put $user_info = fetch_user_info( $_SESSION['uid']); its still the same
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: cannot edit profile
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.
Looking back at what Temor said, I believe I see what they were talking about.
if (empty($errors)){ $grad = htmlentities($_POST['grad']); $drzava = htmlentities($_POST['drzava']); $fan = htmlentities($_POST['fan']); $website = htmlentities($_POST['website']); $user_info = array(); $user_info['grad'] = "$grad"; $user_info['drzava'] = "$drzava"; $user_info['fan'] = "$fan"; $user_info['website'] = "$website"; }else{ $user_info = fetch_user_info($_SESSION['uid']); } ?> <?php mysql_query("UPDATE `users` SET `grad` = '{$grad}', `drzava` = '{$drzava}',`fan` = '{$fan}', `website` = '{$website}' WHERE `uid`='{$uid}'"); ?>Move your query so that it looks like this:
if (empty($errors)){ $grad = htmlentities($_POST['grad']); $drzava = htmlentities($_POST['drzava']); $fan = htmlentities($_POST['fan']); $website = htmlentities($_POST['website']); mysql_query("UPDATE `users` SET `grad` = '{$grad}', `drzava` = '{$drzava}',`fan` = '{$fan}', `website` = '{$website}' WHERE `uid`='{$uid}'"); $user_info = array(); $user_info['grad'] = "$grad"; $user_info['drzava'] = "$drzava"; $user_info['fan'] = "$fan"; $user_info['website'] = "$website"; }else{ $user_info = fetch_user_info($_SESSION['uid']); } ?>
<?php while(!$succeed = try()); ?>
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
Re: cannot edit profile
its still the same
edit.profile.php
edit.profile.php
<?php session_start(); include('core/init.inc.php'); if(isset($_POST['username'])){ $errors = array(); } if(isset($_POST['grad'])){ $errors = array(); } if(isset($_POST['drzava'])){ $errors = array(); } if(isset($_POST['fan'])){ $errors = array(); } if(isset($_POST['website'])){ $errors = array(); } if (empty($errors)){ $grad = htmlentities($_POST['grad']); $drzava = htmlentities($_POST['drzava']); $fan = htmlentities($_POST['fan']); $website = htmlentities($_POST['website']); mysql_query("UPDATE `users` SET `grad` = '{$grad}', `drzava` = '{$drzava}',`fan` = '{$fan}', `website` = '{$website}' WHERE `uid`='{$uid}'"); $user_info = array(); $user_info['grad'] = "$grad"; $user_info['drzava'] = "$drzava"; $user_info['fan'] = "$fan"; $user_info['website'] = "$website"; }else{ $user_info = fetch_user_info($_SESSION['uid']); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>Global Betting</title> </head> <body> <div> <?php 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>'; } ?> <?php if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']) && !empty($_SESSION['uid'])) { ?> </div> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method ="POST"> <div> <label for="grad">Username</label> <input type="text" name="username" id="username" value="<?php echo $user_info ['username']; ?>" /> </div><div> <label for="grad">Grad</label> <input type="text" name="grad" id="grad" value="<?php echo $user_info['grad']; ?>" /> </div> <div> <label for="drzava">Drzava</label> <input type="text" name="drzava" id="drzava" value="<?php echo $user_info ['drzava']; ?>" /> </div> <div> <label for="fan">Fan</label> <input type="text" name="fan" id="fan" value="<?php echo $user_info ['fan']; ?>" /> </div> <div> <label for="grad">Website</label> <input type="text" name="website" id="website" value="<?php echo $user_info ['website']; ?>" /> </div> <div> <input type="submit" value="Update" /> </div> </form> </body> </html> <?php } elseif(!empty($_POST['username']) && !empty($_POST['password'])) { $username = mysql_real_escape_string($_POST['username']); $password = md5(mysql_real_escape_string($_POST['password'])); $checklogin = mysql_query("SELECT * FROM users WHERE username = '".$username."' AND password = '".$password."'"); if(mysql_num_rows($checklogin) == 1) { $row = mysql_fetch_array($checklogin); $_SESSION['Username'] = $username; $_SESSION['LoggedIn'] = 1; $_SESSION['uid'] = $row['uid']; 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 } ?>
- leverkusen
- Posts: 69
- Joined: Sun Nov 18, 2012 10:09 pm
- Location: Belgrade
- Contact:
Re: cannot edit profile
LOL i dont know what else to do any suggestions?
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm