ecabrera Posted August 12, 2011 Share Posted August 12, 2011 hello is this the right way to for a drop down box the drop box is on the sex category $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>Bio/About:</td> <td><textarea name='bio' cols='35' rows='5' class='textbox'>$bio</textarea></td> </tr> <tr> Select a Sex:<br /> <select name="sex"> <option value="Female">Female</option> <option value="Male">Male</option> </select>:<br /> </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"; Quote Link to comment https://forums.phpfreaks.com/topic/244635-form/ Share on other sites More sharing options...
AyKay47 Posted August 12, 2011 Share Posted August 12, 2011 yes, you will retrieve the value by using $_POST['sex']; Quote Link to comment https://forums.phpfreaks.com/topic/244635-form/#findComment-1256519 Share on other sites More sharing options...
ecabrera Posted August 12, 2011 Author Share Posted August 12, 2011 when i select a sex and typed in my password to save it doesnt save it <?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 = fixtext($_POST['bio']); $sex = fixtext($_POST['sex']); $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 sex mysql_query("UPDATE users SET sex='$sex' 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']; $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>Bio/About:</td> <td><textarea name='bio' cols='35' rows='5' class='textbox'>$bio</textarea></td> </tr> <tr> <td>Gender:</td> <td><select> <option>Female</option> <option>Male</option> </select> </td> <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"; Quote Link to comment https://forums.phpfreaks.com/topic/244635-form/#findComment-1256528 Share on other sites More sharing options...
AyKay47 Posted August 12, 2011 Share Posted August 12, 2011 only thing that stands out to me is the very top condition.. if ($username) is this condition being met? if its not.. none of your script will run in the condition.. where is $username set before this..? Quote Link to comment https://forums.phpfreaks.com/topic/244635-form/#findComment-1256531 Share on other sites More sharing options...
ecabrera Posted August 12, 2011 Author Share Posted August 12, 2011 this is part of the the scirpt and heres the rest is you want it this all happen when i add the sex variable and then when i tried to save the rest would save except sex <?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 = fixtext($_POST['bio']); $sex = fixtext($_POST['sex']); $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 sex mysql_query("UPDATE users SET sex='$sex' 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']; $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>Bio/About:</td> <td><textarea name='bio' cols='35' rows='5' class='textbox'>$bio</textarea></td> </tr> <tr> <td>Gender:</td> <td><select> <option>Female</option> <option>Male</option> </select> </td> <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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/244635-form/#findComment-1256535 Share on other sites More sharing options...
AyKay47 Posted August 12, 2011 Share Posted August 12, 2011 the code that you are showing me now is different then before, now you don't have values for you options.. <td><select name="sex"> <option value="Female">Female</option> <option value="Male">Male</option> </select> need the values and name Quote Link to comment https://forums.phpfreaks.com/topic/244635-form/#findComment-1256541 Share on other sites More sharing options...
ecabrera Posted August 12, 2011 Author Share Posted August 12, 2011 if i put that my whoole page wont show up Quote Link to comment https://forums.phpfreaks.com/topic/244635-form/#findComment-1256551 Share on other sites More sharing options...
AyKay47 Posted August 12, 2011 Share Posted August 12, 2011 that doesn't make sense.. do you have error_reporting set to E_ALL..? what errors do you receive? Quote Link to comment https://forums.phpfreaks.com/topic/244635-form/#findComment-1256552 Share on other sites More sharing options...
ecabrera Posted August 12, 2011 Author Share Posted August 12, 2011 i was talking about this <select name="sex"> <option value="male">Jr.High</option> <option value="felmalel">HighSchool</option></select> when i this my whole page doesnt show up but when i add this <td>Gender:</td> <td><select> <option>Female</option> <option>Male</option> </select> </td> i get this Undefined index: sex in /home/ecabrera/public_html/edit_profile.php on line 20 $sex = fixtext($_POST['sex']); Quote Link to comment https://forums.phpfreaks.com/topic/244635-form/#findComment-1256557 Share on other sites More sharing options...
ecabrera Posted August 12, 2011 Author Share Posted August 12, 2011 help Quote Link to comment https://forums.phpfreaks.com/topic/244635-form/#findComment-1256594 Share on other sites More sharing options...
ecabrera Posted August 12, 2011 Author Share Posted August 12, 2011 i get this Undefined index: sex in /home/ecabrera/public_html/edit_profile.php on line 20 $sex = fixtext($_POST['sex']); Quote Link to comment https://forums.phpfreaks.com/topic/244635-form/#findComment-1256616 Share on other sites More sharing options...
AyKay47 Posted August 13, 2011 Share Posted August 13, 2011 simply means you are defining an index that does not carry a value.. you can use isset or empty to check for a value first.. Quote Link to comment https://forums.phpfreaks.com/topic/244635-form/#findComment-1256674 Share on other sites More sharing options...
jcbones Posted August 13, 2011 Share Posted August 13, 2011 the code that you are showing me now is different then before, now you don't have values for you options.. <td><select name="sex"> <option value="Female">Female</option> <option value="Male">Male</option> </select> need the values and name If value is NOT set, then the name is sent instead. <option value"female">Female</option> //valid, and female is sent. <option>Male</option> //valid, and Male is sent. Common mis-conception, and valid syntax that I see "corrected" many times. http://www.w3.org/MarkUp/html-spec/html-spec_8.html The problem here is the fact that you didn't provide a name for the select element. <select name="sex"> Without that, no index in the POST array will be present. Quote Link to comment https://forums.phpfreaks.com/topic/244635-form/#findComment-1256682 Share on other sites More sharing options...
AyKay47 Posted August 13, 2011 Share Posted August 13, 2011 the code that you are showing me now is different then before, now you don't have values for you options.. <td><select name="sex"> <option value="Female">Female</option> <option value="Male">Male</option> </select> need the values and name If value is NOT set, then the name is sent instead. <option value"female">Female</option> //valid, and female is sent. <option>Male</option> //valid, and Male is sent. Common mis-conception, and valid syntax that I see "corrected" many times. http://www.w3.org/MarkUp/html-spec/html-spec_8.html The problem here is the fact that you didn't provide a name for the select element. <select name="sex"> Without that, no index in the POST array will be present. the point about needing only the name or value is a case by case exception.. in this case, he needs both Quote Link to comment https://forums.phpfreaks.com/topic/244635-form/#findComment-1256693 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.