Jump to content

Php Require Question


JackW

Recommended Posts

I am working on a website where I would like to include or require a line of code within a mysql query. Is this possible?I can write the page and everything works fine. However as the query is repeated several times and on several pages and also needs to be changed on occasion I would like to use the require function so I would only have to change it once to have it changed in all applications.Just a piece of the code is included in the text box for reference. As I said when I write the entire code in the pages it works fine. Just looking for a way to include it without writing it many times.

echo '<input type="hidden" name="item_name" value="';echo ($row ['title'] );echo '"><input type="hidden" name="item_number" value="';echo ($row ['stock'] );echo '"><input type="hidden" name="amount" value="';echo $shipped;echo '">';

When I use the require function, of course it places the code on the html page with echo ' and '; showing on the page instead of allowing it to be a part of the php mysql function.Thanks in advance for any help you may be able to give.

Link to comment
Share on other sites

What does this have to do with MySQL? It looks like you're trying to use PHP to include HTML content. Keep in mind that include files also need the PHP tags if you want the code parsed as PHP code instead of just outputted.

Link to comment
Share on other sites

What does this have to do with MySQL? It looks like you're trying to use PHP to include HTML content. Keep in mind that include files also need the PHP tags if you want the code parsed as PHP code instead of just outputted.
You are correct in that what I am getting is the html content. On the complete page I have the php tags and it connects to the data base to get the information that would be included in the sample script. It is likely that what I want to do can not be done.When I include the php tags it does not allow the content from the data base to be inserted. I could include the complete code in the part that is accessed by require, but that would mean opening and closing the data base 10 times on the page. I would enclude the entire code for the page but there is 1067 lines on the page.I think that copy and paste may be the answer as it will work that way. Just looking for a simpler way to do it. Thanks for your help.
Link to comment
Share on other sites

I'm sure there's a way to do what you need to do, I'm just not real clear what you're trying to do. You can put SQL statements in an include file in variables, and include the file on several pages to access the different SQL statements, or you can include entire pieces of code that get a certain result set from the database. You can include literally any PHP code, I guess I'm just not clear specifically what you're trying to do.

Link to comment
Share on other sites

I'm sure there's a way to do what you need to do, I'm just not real clear what you're trying to do. You can put SQL statements in an include file in variables, and include the file on several pages to access the different SQL statements, or you can include entire pieces of code that get a certain result set from the database. You can include literally any PHP code, I guess I'm just not clear specifically what you're trying to do.
Thank you and please do not spend a lot of time here as copy and paste will work.I will try to explain what I am trying to do.I have a data base with 3 tables. One contains product information. Item name, number, and price.One contains customer information. Customer Number, City, State, County.One contains tax rates for the City, State, and County where my client is required to collect sales tax when shipped to that City, State, and County.From the product table I can create variables for the product informationI can connect to the data base and with the Customer Number get the City State and County. Take that information to the tax rate tables and get the City, County and State tax rates and add those three to come up with a tax rate for the sale.Those variables then need to be placed in the shopping cart button form. This shopping cart button form is what I would like to insert with the require function. See the sample code.
<?phpecho '<form target="cart" action="https://www.cart_URL" method="post"><input type="hidden" name="business" value="Bussiness_Code"><input type="hidden" name="item_name" value="';echo $title;echo '"><input type="hidden" name="item_number" value="';echo $stocknumber;echo '"><input type="hidden" name="amount" value="';echo $cost;echo '">';echo '<input type="hidden" name="tax_rate" value="'echo $tax_rate;echo '">';echo '<input type="hidden" name="add" value="1"><input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_SM.gif:NonHosted"><input type="image" src="cart_button" border="0" name="submit" alt="Add to Cart Button"><img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></form>';?>

When I use the php opening and closing, it doesn't let me use the variables I have created.When I do not use the php opening and closing it writes it as html and of course doesn't let me insert the variables I have created.I can copy and paste the code (without the open php and close php) in each place it is needed and it will work. Note: I did remove some lines from the total button code so it may contain errors that are not in the complete code.Thanks again for your help.

Link to comment
Share on other sites

Including a file in PHP is essentially the same thing as copying and pasting the code, when the code gets executed it just inserts whatever was in the included file into where the include statement was. So, any variables that you have defined in the parent file should also be defined in the include file. If the echo statements aren't printing values for the variables, it sounds like the variables aren't defined when the file gets included.

Link to comment
Share on other sites

Including a file in PHP is essentially the same thing as copying and pasting the code, when the code gets executed it just inserts whatever was in the included file into where the include statement was. So, any variables that you have defined in the parent file should also be defined in the include file. If the echo statements aren't printing values for the variables, it sounds like the variables aren't defined when the file gets included.
Thanks, I will play with it some more. Just knowing that it should work helps a lot. Maybe I have some brackets in the wrong place.
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...