Jump to content

[SOLVED] Selecting a value in an option within PHP


Twister1004

Recommended Posts

Hey everyone, just a slight problem. I I'm kinda thinking about it too hard and confusing myself about how to call a value from a select in Hmtl.

 

objective: Can ya help me figure out how to call its value?

 

info:

 

Well, as i described, this is basically a FORM going through with values of a select option.

This here is the layout of the stuff.

<form METHOD="POST" ACTION="">
<table width="396" border="1" cellspacing="1" cellpadding="2">
  <tr>
    <td><center>Your Age:</center></td>
    <td><center><input type="text" name="age" maxlength="2" ></center></td>
  </tr>
  <tr>
    <td><center>E-mail:<br/> Please do not fake your E-mail</center></td>
    <td><center><input type="text" name="email" maxlength="30" ></center></td>
  </tr>
  <tr>
    <td><center>Date of Birth:<br/>YYYY-MM-DD</center></td>
    <td><center><input type="text" name="dob" maxlength="10" ></center></td>
  </tr>
  <tr>
    <td><center>Second or Real Life?</center></td>
    <td><center>
			<select name="life">
			<option value="Real">Real Life</option>
			<option value="Second" selected="selected">Second Life</option>
			</select>
	</center></td>
  </tr>
  <tr>
    <td><center>Looking for:</center></td>
    <td><center>	
			<select name="looking">
			<option value="Friends" selected="selected">Friends</option>
			<option value="Men">Male</option>
			<option value="Women">Female</option>
			</select>
	</center></td>
  </tr>
  <tr>
    <td><center>Sexuality:</center></td>
    <td><center>
			<select name="going">
			<option value="Straight">Straight</option>
			<option value="Gay">Gay</option>
			<option value="Bi">Bi</option>
			</select>
	</center></td>
  </tr>
  <tr>
    <td><center>Status:</center></td>
    <td><center>
			<select name="status">
			<option value="unknown">Not Telling</option>
			<option value="Single">Single</option>
			<option value="Married">Married</option>
			</select>
	</center></td>
  </tr>
</table>

<input name="submit" type="submit" id="submit" value="Submit" />
</form>

 

Now what I don't get is how to call the value from a select option.

here is my php script for it so far

<?php

if(!isset($_POST['submit'])){
// echo "Sorry, your information could not be completed at this time. Please contact an Admin.";
}
else{
isset($_SESSION['login_user']);
$age = mysql_real_escape_string($_POST['age']);
$email = mysql_real_escape_string($_POST['email']);
$dob = mysql_real_escape_string($_POST['dob']);
}
?>

 

As you see, I havent done anything with the ones from the select option.

 

Any hints or tips? =)

Link to comment
Share on other sites

If you are asking what I think you are its exactly as with the other ones

$status = mysql_real_escape_string($_POST['status']);
$going = mysql_real_escape_string($_POST['going']);
$looking = mysql_real_escape_string($_POST['looking']);
$life = mysql_real_escape_string($_POST['life']);

 

PHP will just get the "value" of selected option in the box

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.