Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6660957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:13:11+00:00 2026-05-26T02:13:11+00:00

I was trying to get the selected value from the <select> tag in PHP,

  • 0

I was trying to get the selected value from the <select> tag in PHP, but I get errors.

These is what I have done,

HTML

<select name="gender">
<option value="select">  Select </option>
<option value="male">    Male   </option>
<option value="female">  Female </option>
</select>

PHP script

$Gender  = $_POST["gender"];

but i get these error

Notice: Undefined index: gender in C:\xampp\htdocs\omnama\signup.php on line 7

php script

$Gender  = isset($_POST["gender"]); ' it returns a empty string ? why ?

HTML

<form name="signup_form"  action="./signup.php" onsubmit="return validateForm()"   method="post">
<table> 
  <tr> <td> First Name    </td><td> <input type="text" name="fname" size=10/></td></tr>
  <tr> <td> Last Name     </td><td> <input type="text" name="lname" size=10/></td></tr>
  <tr> <td> Your Email    </td><td> <input type="text" name="email" size=10/></td></tr>
  <tr> <td> Re-type Email </td><td> <input type="text" name="remail"size=10/></td></tr>
  <tr> <td> Password      </td><td> <input type="password" name="paswod" size=10/> </td></tr>
  <tr> <td> Gender        </td><td> <select name="gender">
  <option>                Select </option>    
  <option value="male">   Male   </option>
  <option value="female"> Female </option></select></td></tr> 
  <tr> <td> <input type="submit" value="Sign up" id="signup"/> </td> </tr>
 </table>
 </form>

This is my php script

  <?php
  $con     = mysql_connect("localhost","root","");
  $fname   = $_POST["fname"];
  $lname   = $_POST["lname"];
  $email   =  $_POST["email"];
  $paswod  = $_POST["paswod"];
  $Gender  = $_POST["gender"];
  mysql_select_db("homepage");

  if(mysql_num_rows(mysql_query("SELECT Email FROM users WHERE Email = '$email'",$con)))
  {
  echo "userid is already there";
  }
  else
  { 
  $sql= "INSERT INTO users (FirstName, LastName,Email,Password,Gender)
  VALUES
  ('$fname','$lname','$email','$paswod','$Gender')";

  if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
  echo "created";
  }
 ?> 

Please help me with these. I have to get the selected index value in the PHP.

I have read this link to use <select> tag in PHP.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:13:11+00:00Added an answer on May 26, 2026 at 2:13 am

    Your form is valid. Only thing that comes to my mind is, after seeing your full html, is that you’re passing your “default” value (which is not set!) instead of selecting something.
    Try as suggested by @Vina in the comment, i.e. giving it a selected option, or writing a default value

    <select name="gender">
    <option value="default">Select </option>    
    <option value="male">   Male   </option>
    <option value="female"> Female </option>
    </select>
    

    OR

    <select name="gender">
    <option value="male" selected="selected">   Male   </option>
    <option value="female"> Female </option>
    </select>
    

    When you get your $_POST vars, check for them being set; you can assign a default value, or just an empty string in case they’re not there.

    Most important thing, AVOID SQL INJECTIONS:

    //....
    $fname   = isset($_POST["fname"]) ? mysql_real_escape_string($_POST['fname']) : '';
    $lname   = isset($_POST['lname']) ? mysql_real_escape_string($_POST['lname']) : '';
    $email   = isset($_POST['email']) ? mysql_real_escape_string($_POST['email']) : '';
    you might also want to validate e-mail:
    if($mail = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
    {
      $email = mysql_real_escape_string($_POST['email']);
    }
    else
    {
      //die ('invalid email address');
      // or whatever, a default value? $email = '';
    }
    $paswod  = isset($_POST["paswod"]) ? mysql_real_escape_string($_POST['paswod']) : '';
    $gender  = isset($_POST['gender']) ? mysql_real_escape_string($_POST['gender']) : '';
    
    $query = mysql_query("SELECT Email FROM users WHERE Email = '".$email."')";
    if(mysql_num_rows($query)> 0)
    {
      echo 'userid is already there';
    }
    else
    {
     $sql = "INSERT INTO users (FirstName, LastName, Email, Password, Gender)
             VALUES ('".$fname."','".$lname."','".$email."','".paswod."','".$gender."')";
    $res = mysql_query($sql) or die('Error:'.mysql_error());
    echo 'created';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi am trying to get the value of p:selectOneMenu from jquery , but i
I'm trying to get the selected value from a drop down list via jQuery.
I am trying to get the value from the radio boxes/button with php. The
Hi I have a Select list liek so: <select id=cardtype name=cardtype> <option selected='y' value=debit-0.00-50.00>Debit1</option>
I am trying to get the selected row value from a DataGrid in WPF,
I'm trying to get the integer value of The number selected of the item.
I am trying to get the selected option from a dropdown and populate another
I'm trying to get the HTML of a selected object with jQuery. I am
Trying to get a value from a dropdown to fire a console.log('test') upon finding
I have an Oracle database where I'm trying to select a user field from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.