anatak Posted May 10, 2006 Share Posted May 10, 2006 Is it possible for a switch statement to check against the value of a variable ?Here is what I would like to do:[code]$case01 = button_caption(1);$case02 = button_caption(2);switch ($_REQUEST['submit']){ case '$case01 ' : code for case01; break; case '$case02 ' : code for case02; break;}[/code]is this possible ?I keep running into errors because of the single quotes.thanksanatak Quote Link to comment Share on other sites More sharing options...
DepretioN Posted May 10, 2006 Share Posted May 10, 2006 Yes its possible and you answered your own question. Use double quotes. Quote Link to comment Share on other sites More sharing options...
trq Posted May 11, 2006 Share Posted May 11, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Use double quotes.[/quote]Variables dont need to be within quotes.[code]$case01 = button_caption(1);$case02 = button_caption(2);switch ($_REQUEST['submit']){ case $case01: code for case01; break; case $case02: code for case02; break;}[/code] Quote Link to comment Share on other sites More sharing options...
anatak Posted May 11, 2006 Author Share Posted May 11, 2006 thanksIt works indeed as you said.I could have sworn that I tried what you told me but apparantly not Now I have another problem with IEIn Mozilla this works without problems[code]<script language="Javascript" type="text/javascript"><!--document.write('<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'] . "?page=register"?>">');--></script><TABLE width ="100%"><TR><td>SOME FIELDS TO GET DATA</td></tr><TR><TD colspan ="2"><BUTTON name="submit" value="<?php echo $button=button_caption(5); ?>" type="submit"><?php echo $button=button_caption(5); ?></BUTTON> <BUTTON name="submit" value="<?php echo $button=button_caption(6); ?>" type="submit"><?php echo $button=button_caption(6); ?></BUTTON> <BUTTON name="clear" value="<?php echo $button=button_caption(2); ?>" type="reset"><?php echo $button=button_caption(2); ?></BUTTON></TD></TR>[/code]but in IE the browser does not detect what button is pushed.It always thinks that the last "submit" button is pushedso in the page that receives the data it always thinks it has to run the button_caption(6) (review)script[code]<?php//echo 'webpage = register<BR>';if(!isset($_REQUEST['submit'])){ include("home/home.inc");// echo "home";}else{ echo "submit " . $_REQUEST['submit']."</br>";//this is always review[/code]any idea how you can use more than one submit button in a form with IE and using button ? Or am I condemned to use input type instead ?thank you so muchanatak Quote Link to comment Share on other sites More sharing options...
.josh Posted May 13, 2006 Share Posted May 13, 2006 you gave both your buttons the same name. Quote Link to comment Share on other sites More sharing options...
anatak Posted May 14, 2006 Author Share Posted May 14, 2006 yes but if I use a $_REQUEST['submit'] the button has to be called submit I thought ?or would this code work ?[code]<TR><TD colspan ="2"><BUTTON name="submit" value="<?php echo $button=button_caption(5); ?>" type="submit"><?php echo $button=button_caption(5); ?></BUTTON> <BUTTON name="submit" value="<?php echo $button=button_caption(6); ?>" type="submit"><?php echo $button=button_caption(6); ?></BUTTON> <BUTTON name="clear" value="<?php echo $button=button_caption(2); ?>" type="reset"><?php echo $button=button_caption(2); ?></BUTTON></TD></TR>[/code]and receiving the value like this[code]$case01 = button_caption(1);$case02 = button_caption(2);switch ($_REQUEST['submit']){ case $case01: code for case01; break; case $case02: code for case02; break;}[/code] Quote Link to comment Share on other sites More sharing options...
anatak Posted December 12, 2007 Author Share Posted December 12, 2007 problem solved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.