Jump to content

Archived

This topic is now archived and is closed to further replies.

anatak

[SOLVED] switch statement

Recommended Posts

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.

thanks
anatak

Share this post


Link to post
Share on other sites
[!--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]

Share this post


Link to post
Share on other sites
thanks

It 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 IE
In 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 pushed

so 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 much
anatak

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

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.