ecabrera Posted August 12, 2011 Share Posted August 12, 2011 i get this error when i try to save my profile Notice: 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/244652-error/ Share on other sites More sharing options...
WebStyles Posted August 12, 2011 Share Posted August 12, 2011 maybe it should be: $sex = fixtext($_POST["sex"]); although that's very little info and code for us to figure it out. try something like this: if(isset($_POST['sex'])){ echo 'variable exists.'; }else{ echo 'Variable did not reach this page'; } p.s. I'm not even going to ask what the content of that variable is, or did you mean 'gender' ... Quote Link to comment https://forums.phpfreaks.com/topic/244652-error/#findComment-1256632 Share on other sites More sharing options...
ecabrera Posted August 12, 2011 Author Share Posted August 12, 2011 yes i mean gender but i prefer sex i dont why if (@$_POST['savebtn']){ $firstname = fixtext($_POST['firstname']); $lastname = fixtext($_POST['lastname']); $email = fixtext($_POST['email']); $youtube = fixtext($_POST['youtube']); $bio = fixtext($_POST['bio']); $sex = $_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/244652-error/#findComment-1256635 Share on other sites More sharing options...
WebStyles Posted August 12, 2011 Share Posted August 12, 2011 Gender:</td> <td><select> <option>Female</option> <option>Male</option> </select> is missing the select name and values. Should be Gender:</td> <td><select name="sex"> <option value="Female">Female</option> <option value="Male">Male</option> </select> Quote Link to comment https://forums.phpfreaks.com/topic/244652-error/#findComment-1256638 Share on other sites More sharing options...
ecabrera Posted August 12, 2011 Author Share Posted August 12, 2011 i tired that already and it give me a blank page saying server error Quote Link to comment https://forums.phpfreaks.com/topic/244652-error/#findComment-1256642 Share on other sites More sharing options...
Acoon Posted August 12, 2011 Share Posted August 12, 2011 I dont have time to give you the entire answer answer, but the input for sex is a select box, and for what i see, you are handling it wrong. Read up on how to handle the kind of input sex is. Br, Acoon Quote Link to comment https://forums.phpfreaks.com/topic/244652-error/#findComment-1256643 Share on other sites More sharing options...
ecabrera Posted August 12, 2011 Author Share Posted August 12, 2011 i did and it gives me errors thats the coorect way but when i tried that it give me server error Gender: <select name="sex"> <option value="male">male</option> <option value="female">female</option></select> Quote Link to comment https://forums.phpfreaks.com/topic/244652-error/#findComment-1256646 Share on other sites More sharing options...
WebStyles Posted August 12, 2011 Share Posted August 12, 2011 escape quotes or change to single quotes: <select name='sex'> <option value='male'>male</option> <option value='female'>female</option></select> or <select name=\"sex\"> <option value=\"male\">male</option> <option value=\"female\">female</option></select> Quote Link to comment https://forums.phpfreaks.com/topic/244652-error/#findComment-1256650 Share on other sites More sharing options...
ecabrera Posted August 12, 2011 Author Share Posted August 12, 2011 ok the first one work thanks Quote Link to comment https://forums.phpfreaks.com/topic/244652-error/#findComment-1256653 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.