ecabrera Posted August 25, 2011 Share Posted August 25, 2011 hello i need help when users go to there edit profile page insert stuff and save then go back and edit the selects are back the the first option for exampe i save me gender as female and when i come back and edit it says male heres the code for that page <?php $title = "Edit Profile"; ?> <?php require("styles/top.php"); ?> <div id='left'> <?php if ($username){ require ("scripts/connect.php"); if (@$_POST['savebtn']){ $firstname = fixtext($_POST['firstname']); $lastname = fixtext($_POST['lastname']); $email = fixtext($_POST['email']); $youtube = fixtext($_POST['youtube']); $bio = $_POST['bio']; $music = $_POST['music']; $movies = $_POST['movies']; $tv = $_POST['tv']; $sex = fixtext($_POST['sex']); $status = fixtext($_POST['status']); $education= fixtext($_POST['education']); $password = fixtext($_POST['password']); $name = $_FILES['avatar']['name']; $type = $_FILES['avatar']['type']; $size = $_FILES['avatar']['size']; $tmpname = $_FILES['avatar']['tmp_name']; $ext = substr($name, strrpos($name, '.')); if ($firstname && $lastname && $email && $password){ if (strstr($email, "@") && strstr($email, ".") && (strlen($email) >= 6)){ $password = md5(md5($password)); $query = mysql_query("SELECT * FROM users WHERE id='$userid' AND password='$password'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ // set firstname mysql_query("UPDATE users SET first_name='$firstname' WHERE id='$userid'"); // set lastname mysql_query("UPDATE users SET last_name='$lastname' WHERE id='$userid'"); // set email mysql_query("UPDATE users SET email='$email' WHERE id='$userid'"); // set youtube mysql_query("UPDATE users SET youtube='$youtube' WHERE id='$userid'"); // set music mysql_query("UPDATE users SET music='$music' WHERE id='$userid'"); // set movies mysql_query("UPDATE users SET movies='$movies' WHERE id='$userid'"); // set tv mysql_query("UPDATE users SET tv='$tv' WHERE id='$userid'"); // set sex mysql_query("UPDATE users SET sex='$sex' WHERE id='$userid'"); // set status mysql_query("UPDATE users SET status='$status' WHERE id='$userid'"); // education mysql_query("UPDATE users SET education='$education' WHERE id='$userid'"); // set bio mysql_query("UPDATE users SET bio='$bio' WHERE id='$userid'"); if ($name){ $avatarname = "$username"."$ext"; move_uploaded_file($tmpname, "avatars/$avatarname"); // set bio mysql_query("UPDATE users SET avatar='$avatarname' WHERE id='$userid'"); } echo "Your information has been saved."; } else echo "Your password was incorrect."; } else echo "You did not provide a valid email."; } else echo "You did not provied the required info."; } $query = mysql_query("SELECT * FROM users WHERE id='$userid'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ $row = mysql_fetch_assoc($query); $id = $row['id']; $firstname = $row['first_name']; $lastname = $row['last_name']; $email = $row['email']; $avatar = $row['avatar']; $bio = $row['bio']; $sex = $row['sex']; $status = $row['status']; $education = $row['sex']; $music = $row['music']; $movies = $row['movies']; $tv = $row['tv']; $youtube = $row['youtube']; $lastlogin = $row['last_login']; $active = $row['active']; $locked = $row['locked']; $date = $row['date']; } else echo "An error occured while connecting to the database."; $infoform = "<form action='edit_profile.php' method='post' enctype='multipart/form-data'> <table cellspacing='10px'> <tr> <td></td> <td><font color='red'>*</font> are required</td> </tr> <tr> <td>First Name:</td> <td><input type='text' name='firstname' class='textbox' size='35' value='$firstname'><font color='red'>*</font></td> </tr> <tr> <td>Last Name:</td> <td><input type='text' name='lastname' class='textbox' size='35' value='$lastname'><font color='red'>*</font></td> </tr> <tr> <td>Email:</td> <td><input type='text' name='email' class='textbox' size='35' value='$email'><font color='red'>*</font></td> </tr> <tr> <td>Avatar:</td> <td><input type='file' name='avatar'></td> </tr> <tr> <tr> <td>Youtube Username:</td> <td><input type='text' name='youtube' class='textbox' size='35' value='$youtube'></td> </tr> <tr> <td>About:</td> <td><textarea name='bio' cols='35' rows='5' class='textbox'>$bio</textarea><br><br /><font color='black'>You can add embed code here!Width must be less then 250px</font></td> </tr> <tr> <td>Music Player:</td> <td><textarea name='music' cols='35' rows='5' class='textbox'>$music</textarea><br><br /><font color='black'>You can add embed music player here!</font></td> </tr> <tr> <td>Movies:</td> <td><textarea name='movies' cols='35' rows='5' class='textbox'>$movies</textarea><br><br /><font color='black'>You can add embed code here! Width must be less then 250px</font></td> </tr> <tr> <td>TV:</td> <td><textarea name='tv' cols='35' rows='5' class='textbox'>$tv</textarea><br><br /><font color='black'>You can add embed code here!Width must be less then 250px</font></td> </tr> <tr> <td>Gender:</td> <td><select name='sex'> <option value='Male'>Male</option> <option value='Female'>Female</option></select> </td> </tr> <tr> <td>Status</td> <td><select name='status'> <option value='Single'>Single</option> <option value='Married'>Married</option> <option value='Widowed'>Widowed</option> <option value='Domestic'>Domestic</option> <option value='Cohabitation'>Cohabitation</option> <option value='Divorced'>Divorced</option></select></td> </tr> <tr> <td>Education</td> <td><select name='education'> <option value='Jr.High'>Jr.High</option> <option value='High School'>High School</option> <option value='College'>College</option></select></td> </tr> <tr> <td>Current Password:</td> <td><input type='password' name='password' class='textbox' size='35'></td> </tr> <tr> <td></td> <td><input type='submit' name='savebtn' value='Save Changes' class='button'></td> </tr> </table> </form>"; echo "$infoform"; /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// echo "<br /><hr><br />"; $passform = "<form action='edit_profile.php' method='post'> <table cellspacing='10px'> <tr> <td>Current Password:</td> <td><input type='text' name='oldpass' class='textbox' size='35'></td> </tr> <tr> <td>New Password:</td> <td><input type='password' name='newpass' class='textbox' size='35'></td> </tr> <tr> <td>Confirm Password:</td> <td><input type='password' name='confirmpass' class='textbox' size='35'></td> </tr> <tr> <td></td> <td><input type='submit' name='passbtn' class='button' value='Save Changes' size='35'></td> </tr> </table></form>"; if (@$_POST['passbtn']){ $oldpass = fixtext($_POST['oldpass']); $newpass = fixtext($_POST['newpass']); $confirmpass = fixtext($_POST['confirmpass']); if ($oldpass && $newpass && $confirmpass){ if ($newpass == $confirmpass){ $oldpass = md5(md5($oldpass)); $newpass = md5(md5($newpass)); $query = mysql_query("SELECT * FROM users WHERE id='$userid' AND password='$oldpass'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ mysql_query("UPDATE users SET password='$newpass' WHERE id='$userid'"); echo "You new password has been set. $passform"; } else echo "Your current password was incorrect. $passform"; } else echo "Your new passwords did not match. $passform"; } else echo "You did not fill in the entire form. $passform"; } else echo "$passform"; } else echo "<font color='red'><center><h1>You must be logged in to view this page.</h1></center></font>"; ?> </div> <div id='right'></div> <?php require("styles/bottom.php"); ?> Link to comment https://forums.phpfreaks.com/topic/245659-seelect/ Share on other sites More sharing options...
MasterACE14 Posted August 25, 2011 Share Posted August 25, 2011 <select name='sex'> <option value='Male'>Male</option> <option value='Female'>Female</option></select> You have 'Male' as the first(default) option. Also you shouldn't suppress errors, notices or warnings. Change this line: if (@$_POST['savebtn']){ to this: if (isset($_POST['savebtn'])){ Link to comment https://forums.phpfreaks.com/topic/245659-seelect/#findComment-1261707 Share on other sites More sharing options...
ecabrera Posted August 25, 2011 Author Share Posted August 25, 2011 ok i added it this <td>Education</td> <td><select name='education'> <option value=''>Select...</option> <option value='Jr.High'>Jr.High</option> <option value='High School'>High School</option> <option value='College'>College</option></select></td> </tr> and still when i save my option and exit then come back i get select.. Link to comment https://forums.phpfreaks.com/topic/245659-seelect/#findComment-1261710 Share on other sites More sharing options...
Pikachu2000 Posted August 25, 2011 Share Posted August 25, 2011 http://www.google.com/search?q=making+form+sticky+php&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a Link to comment https://forums.phpfreaks.com/topic/245659-seelect/#findComment-1261711 Share on other sites More sharing options...
ecabrera Posted August 27, 2011 Author Share Posted August 27, 2011 still i have no clue Link to comment https://forums.phpfreaks.com/topic/245659-seelect/#findComment-1262564 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.