Note that there are some explanatory texts on larger screens.

plurals
  1. POGet post value from a select tag PHP
    primarykey
    data
    text
    <p>Hey I need to get the gender selected from a select tag and then store that value as a variable in php, here's some relevant snippets of both the register.php form and the register_process.php file</p> <p>register.php</p> <pre><code> &lt;form action="register_process.php" method="post"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;Username (to be used for login and display name)&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="username" id="username" onclick="check()"/&gt;&lt;/td&gt; &lt;td id="username_check"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Password&lt;/td&gt; &lt;td&gt;&lt;input type="password" name="password" id="password" onclick="check()"/&gt;&lt;/td&gt; &lt;td id="password_check"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Password (Re-Enter)&lt;/td&gt; &lt;td&gt;&lt;input type="password" name="repassword" id="repassword" onclick="check()"/&gt;&lt;/td&gt; &lt;td id="repassword_check"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Email Address&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="email" id="email" onclick="check()"/&gt;&lt;/td&gt; &lt;td id="email_check"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Email Address (Re-Enter)&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="reemail" id="reemail" onclick="check()"/&gt;&lt;/td&gt; &lt;td id="reemail_check"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Gender&lt;/td&gt; &lt;td&gt; &lt;select name="gender"&gt; &lt;option value="1"&gt;Male&lt;/option&gt; &lt;option value="2"&gt;Female&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;I agree to the terms and conditions&lt;/td&gt; &lt;td&gt;&lt;input type="checkbox" name="tos" id="tos" /&gt;&lt;/td&gt; &lt;td id="tos_check"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td id="valid" colspan="3"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3"&gt;&lt;input type="submit" value="Register" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3"&gt;&lt;a href="login.php"&gt;Cancel&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; </code></pre> <p>there is a ton of javascript I have omitted from this that does very basic validation</p> <p>register_process.php</p> <pre><code> &lt;?php ini_set('display_errors', 'On'); error_reporting(E_ALL | E_STRICT); ?&gt; &lt;?php $connection = mysql_connect(HOST, USERNAME, PASSWORD); if(!$connection) { die("Database connection failed: " . mysql_error()); } $db_select = mysql_select_db(DATABASE, $connection); if(!$db_select) { die("Database selection failed: " . mysql_error()); } $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $repassword = mysql_real_escape_string($_POST['repassword']); $email = mysql_real_escape_string($_POST['email']); $reemail = mysql_real_escape_string($_POST['reemail']); $gender = $_POST['gender']; $tos = mysql_real_escape_string($_POST['tos']); // not being checked yet $errors = 0; $success = 0; // USERNAME CHECK if (preg_match('/^[a-z\d_]{5,20}$/i', $username)) { $user_query = "SELECT * FROM users WHERE user_name = '$username' OR login_name = '$username' LIMIT 1"; $result=mysql_query($user_query); $count=mysql_num_rows($result); if($count==0) { echo "username is available &lt;br/&gt;"; $success++; echo "&lt;br/&gt;1 Passed&lt;br/&gt;"; } else { echo "sorry, that username already exist"; $errors++; echo "&lt;br/&gt;1 Passed&lt;br/&gt;"; } } else { echo "You either need to enter a username, or you have entered a username in an incorrect format."; $errors++; echo "&lt;br/&gt;1 Passed&lt;br/&gt;"; </code></pre> <p>}</p> <pre><code> // PASSWORD CHECK if(preg_match('/^[a-z\d_]{5,20}$/i', $password)) { // password is between 5-10 characters, alpha-numeric (a-z, A-Z, 0-9) and underscores if($password === $repassword) { // password is identical $success++; echo "&lt;br/&gt;2 Passed&lt;br/&gt;"; } else { // passwords do not match $errors++; echo "&lt;br/&gt;2 Passed&lt;br/&gt;"; } } else { echo "Password failed validation"; $errors++; } // EMAIL CHECK if (eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$',$email)) { // user@email.com passes // 1@1.com passes // -@_.com passes // echo "&lt;br/&gt; email is ok"; if($email === $reemail) { // email addresses match $success++; echo "&lt;br/&gt;3 Passed&lt;br/&gt;"; } else { // email address does not match echo "&lt;br/&gt;3 Passed&lt;br/&gt;"; $errors++; } } else { echo "email validation failed &lt;br/&gt;"; $errors++; echo $email; } // Here is the problem, I can't seem to evaluate the correct value, // When I echo out $gender I get nothing, So theres either an issue // in the html form OR in the way I use $gender = $_POST['gender']; if($gender == 1 || $gender == "1" || $gender == '1') { echo "male selected"; } else { echo "female selected"; } ?&gt; </code></pre> <p>what am I missing here guys?, </p> <p>I have been hunting around google to find an answer with no success.</p> <p>heres the error php is giving me:</p> <p>"Notice: Undefined index: gender in register_process.php on line 22"</p> <p>Everything else in the form IS working fine, there are no other issues</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload