dyr Posted March 3, 2012 Share Posted March 3, 2012 Hi, I recently implemented a code to display user profile information. Well, it displays the username and password fine, but the edit function doesn't seem to be working. I edit the information, click submit, get a success message but the username and password didn't change. myprofile.php <?php session_start(); include('config.php'); $sql = mysql_query( "SELECT * FROM users WHERE id='".$_SESSION['id']."'" ); echo "<h2>Profile</h2> <form method='post' action='editprofile.php'> <table>"; $row = mysql_fetch_array($sql); echo "<tr><th>Name: </th><td>".$row['username']."</td></tr> <tr><th>Password: </th><td><input type='password' value='".$row['password']."' disabled='true' /></td></tr>"; echo "</table><br /> <input type='submit' value='edit profile' /> </form>"; ?> editprofile.php <?php include('config.php'); if(isset($_POST['btnedit'])){ $username = $_POST['username']; $password = $_POST['password']; $sql = mysql_query( "UPDATE users SET username='".$username."', password='".$password."' WHERE id='".$_SESSION['id']."'" ); if($sql){ echo "<script>alert('profile updated');window.location='myprofile.php'</script>"; }else{ echo "<script>alert('updating profile failed!');</script>"; } } $sql = mysql_query( "SELECT * FROM users WHERE id='".$_SESSION['id']."'" ); $row = mysql_fetch_array($sql); echo "<h2>Edit profile</h2> <form method='post'> <table> <tr><th>registered:</th><td><input type='text' name='username' value='".$row['username']."'/></td></tr> <tr><th>password:</th><td><input type='password' name='password' value='".$row['password']."'/></td></tr> </table><br /> <input type='submit' name='btnedit' value='update' /> </form>"; ?> Link to comment https://forums.phpfreaks.com/topic/258208-user-profile-not-updating/ Share on other sites More sharing options...
dannyb785 Posted March 3, 2012 Share Posted March 3, 2012 You need to redeclare the session_start() function at the beginning of editprofile.php. You're trying to access $_SESSION['id'] in the UPDATE query, but since the session_start() wasn't executed, the session isn't the same as the previous page. Personally, I always have session_start() in my config.php file so that I never forget to do it Link to comment https://forums.phpfreaks.com/topic/258208-user-profile-not-updating/#findComment-1323603 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.