Jump to content


Photo

(solved) if drop box


  • Please log in to reply
4 replies to this topic

#1 Noctagon

Noctagon
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 25 September 2006 - 11:15 PM

Hi All,

I am totally new to this stuff so thanks in advance for your patience :)

I am trying to run a simple if statement and it is not working as plan.  Perhaps someone could tell me why :)

I have a drop box weaved into my code as follows

<select size="1" name="nomtacyn">
			<option selected>No</option>
			<option>Yes</option>
			</select>

the form action is to run this

<?php

  $nomtacyn = $_POST['nomtacyn'];

  $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
?>
<html>
<head>
</head>
<body>

<?php

	if ($nomtacyn = No) {
	echo "Your have selected No";
	}
	else {
	Echo "You have selected yes";
	}
	
?>

</body>
</html>

Thanks :)

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 25 September 2006 - 11:18 PM

Try recoding your form (which presumably uses the method="post") thus:

<select size="1" name="nomtacyn">
<option value="No" selected="selected">No</option>
<option value="Yes">Yes</option>
</select>

Legend has it that reading the manual never killed anyone.
My site

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 September 2006 - 11:19 PM

Your IF needs two '=' signs and quotes " "...

if ($nomtacyn == "No"){

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#4 Noctagon

Noctagon
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 25 September 2006 - 11:23 PM

Thanks for the speedy reply.......doh.....I said to myself that double equals sign will never get me ;)

Cheers

#5 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 September 2006 - 11:33 PM

It would also be a good idea, as Andy suggested, to out values in your <option> tags, rather than just letting them take the value of the text.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users