Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

dynamicly include contents within html

Posted on 2006-11-18
3
Medium Priority
?
223 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
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
gamebits earned 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

886 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