Note that there are some explanatory texts on larger screens.

plurals
  1. POget the selected index value of <select> tag in php
    primarykey
    data
    text
    <p>I was trying to get the selected value from the <code>&lt;select&gt;</code> tag in PHP, but I get errors. </p> <p>These is what I have done,</p> <p>HTML</p> <pre><code>&lt;select name="gender"&gt; &lt;option value="select"&gt; Select &lt;/option&gt; &lt;option value="male"&gt; Male &lt;/option&gt; &lt;option value="female"&gt; Female &lt;/option&gt; &lt;/select&gt; </code></pre> <p>PHP script</p> <pre><code>$Gender = $_POST["gender"]; </code></pre> <p>but i get these error</p> <pre><code>Notice: Undefined index: gender in C:\xampp\htdocs\omnama\signup.php on line 7 </code></pre> <p>php script</p> <pre><code>$Gender = isset($_POST["gender"]); ' it returns a empty string ? why ? </code></pre> <p>HTML </p> <pre><code>&lt;form name="signup_form" action="./signup.php" onsubmit="return validateForm()" method="post"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; First Name &lt;/td&gt;&lt;td&gt; &lt;input type="text" name="fname" size=10/&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; Last Name &lt;/td&gt;&lt;td&gt; &lt;input type="text" name="lname" size=10/&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; Your Email &lt;/td&gt;&lt;td&gt; &lt;input type="text" name="email" size=10/&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; Re-type Email &lt;/td&gt;&lt;td&gt; &lt;input type="text" name="remail"size=10/&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="paswod" size=10/&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&gt; Select &lt;/option&gt; &lt;option value="male"&gt; Male &lt;/option&gt; &lt;option value="female"&gt; Female &lt;/option&gt;&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="submit" value="Sign up" id="signup"/&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; </code></pre> <p>This is my php script</p> <pre><code> &lt;?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"; } ?&gt; </code></pre> <p>Please help me with these. I have to get the selected index value in the PHP. </p> <p>I have read this <a href="http://www.dreamincode.net/forums/topic/48477-how-to-get-the-select-value-from-the-drop-down-list/" rel="nofollow noreferrer">link</a> to use <code>&lt;select&gt;</code> tag in PHP. </p>
    singulars
    1. This table or related slice is empty.
    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.
 

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