Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-09-2010, 12:40 AM   PM User | #1
codeloffah
New to the CF scene

 
Join Date: Jun 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
codeloffah is an unknown quantity at this point
Else if not working correcting with simple form.

I have a simple form with a drop down box. What I'm trying to do is echo different things depending on what is selected. The problem is that no matter which option is selected, the script echoes the first option.

In other words, it seems to be returning the first 'if' as always true.


The html is this...
Code:
<html>
<body>

<form action="myform.php" method="post">
<p>Customer name: <input type="text" name="name" value="[FIRST]" /><br />
</p>

<p>Service requested.</p>
	<select name="service"> 
		<option id="entry">VIP Entry</option>
		<option id="bottles">Bottle Service</option>
	</select>
	<select name="venue">
		<option id="xs">XS</option>
		<option id="tryst">Tryst</option>
		<option id="haze">Haze</option>
		<option id="other">other</option>
	</select>
<p><input type="submit" value="Send it!"></p>
</form>

</body>
</html>
The php is this...
Code:
<?php echo $_POST["name"] ?>

<?php
if ($_POST['service']="entry") {
  echo "ENTRY"; }
  
elseif ($_POST['service']="bottles") {
  echo "BOTTLES"; }
  
else {
  echo "NOTHING!"; }

?>
codeloffah is offline   Reply With Quote
Old 06-09-2010, 12:44 AM   PM User | #2
met
Regular Coder

 
Join Date: Oct 2009
Location: United Kingdom
Posts: 728
Thanks: 4
Thanked 119 Times in 119 Posts
met has a little shameless behaviour in the past
PHP Code:
<?php echo $_POST["name"]; ?>

<?php
if ($_POST['service']=="entry") {
  
    echo 
"ENTRY"

} elseif (
$_POST['service']=="bottles") {

  echo 
"BOTTLES"

} else {
  
    echo 
"NOTHING!"

}

?>
= is the assignment operator
== is comparison
=== is same type and same value
met is offline   Reply With Quote
Old 06-09-2010, 12:59 AM   PM User | #3
codeloffah
New to the CF scene

 
Join Date: Jun 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
codeloffah is an unknown quantity at this point
I knew it was something simple!

is there any way for the form to post the 'id' of the option instead of the display text?
codeloffah is offline   Reply With Quote
Old 06-09-2010, 09:53 AM   PM User | #4
met
Regular Coder

 
Join Date: Oct 2009
Location: United Kingdom
Posts: 728
Thanks: 4
Thanked 119 Times in 119 Posts
met has a little shameless behaviour in the past
use the value attribute.

<option id="xs" value="this is the value">XS</option>

id is the identifier to "identify" the element.
met is offline   Reply With Quote
Reply

Bookmarks

Tags
drop down, elseif, form, ifthen

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:56 PM.


Advertisement
Log in to turn off these ads.