Jump to content

[SOLVED] switch statement


anatak

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

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

  • 1 year later...
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.