Solved

dynamicly include contents within html

Posted on 2006-11-18
3
202 Views
Last Modified: 2013-11-18
I have the following code:

</tr>

<?php
      if (strcmp($_POST['category'], "boxing") == 0)
      {
            require_once('inc/boxing_sub.inc');
      }
      if (strcmp($_POST['category'], "kickboxing") == 0)
      {
            require_once('inc/kickboxing_sub.inc');
      }
      if (strcmp($_POST['category'], martial") == 0)
      {
            require_once('inc/martial_sub.inc');
      }
      if (strcmp($_POST['category'], "special") == 0)
      {
            require_once('inc/special_sub.inc');
      }
?>

<tr>


as you can see it includes a .inc file as required..... at least i thought i could do that, but the result is an empty page..

if i just did
echo "test"; in the place of the require_once, I get the test echoed out where it should be.

what could be the problem?

thanks
0
Comment
Question by:sakuya_su
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
gamebits earned 500 total points
ID: 17971143
require_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script (from php.net)

it seems to me that you are trying to include different files depending of which if statement is being called.

personnaly on a situation like that i would go with a switch statement.

switch($_POST['category'];)

        {
             case "boxing":

                include ('inc/boxing_sub.inc');

             break;
        }

        {  case "kickboxing":

                 include ('inc/kickboxing.inc');

             break;
         }

etc.

Gamebits
0
 
LVL 10

Author Comment

by:sakuya_su
ID: 17971169
<?php
      if (strcmp($_POST['category'], "boxing") == 0)
      {
            include('inc/boxing_sub.inc');
      }
      if (strcmp($_POST['category'], "kickboxing") == 0)
      {
            include('inc/kickboxing_sub.inc');
      }
      if (strcmp($_POST['category'], martial") == 0)
      {
            include('inc/martial_sub.inc');
      }
      if (strcmp($_POST['category'], "special") == 0)
      {
            include('inc/special_sub.inc');
      }
?>

the above code still generate no contents

but if i did:
<?php
      if (strcmp($_POST['category'], "boxing") == 0)
      {
            echo "why";
        }
?>

if echos why at the correct location..

any ideas?

thanks
0
 
LVL 10

Author Comment

by:sakuya_su
ID: 17971177
hahahaha oh wow that was stupid of me :P

     if (strcmp($_POST['category'], martial") == 0)

missing quote with error report disabled (I just installed a new PHP and the error reporting was on none it seems)

and also $_POST is meant to be $_GET :P

thanks for your help, I will give you the points none the less
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question