Hi , I am new to php and i have a question . I tried searching for answers but couldnt find any .

My Problem :

I have a variable $itemcode and a product.php

say $itemcode = 5 ,

if using the url method of passing variable , it would be
http://www.site.com/product.php?itemcode=5

and i also learned that if i want to use another php file withinone,
the code will be simply :
<?php include("product.php") ; ?>

Apparently , <?php include("product.php?itemcode=5") ; ?> does not work .

My question is that if there is any way i can "combine" these 2 . I mean which i can pass $itemcode = 5 while executing the product.php . Thanks .

    <?php
    $itemcode = 5;
    include "product.php";
    ?>

    will work if product.php references itemcode.

      sorry if i sound stupid , but does "
      " if product.php references itemcode. "
      means declaring $itemcode as a global variable first ?

      or else what do you mean by "references" ? can you please give me a simple example ? i'm really lost ...

        product.php

        <?php
        
        echo $itemcode;
        
        ?>
        

        somefile.php

        <?php
        $itemcode = 5;
        include "product.php";
        ?>
        

        the output of running somefile.php will be 5.

        this is what you were trying to do by passing itemcode in the query string which doesnt work for includes because it includes a file only with no extra parameters.

          Just a suggestion:

          You might want to try to retrieve the itemcode value by:

          $_GET['itemcode']

          in your product.php

            Write a Reply...