Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Where to place my php script in my webpage?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Where to place my php script in my webpage?

Postby inoob » Wed Apr 17, 2013 12:01 pm

I find this a little strange. I have a script that has 2 included .js files, a php script after them and a table below the php script that displays the info from the php script. I noticed when I place the entire script somewhere in the middle of my .php webpage, it shows a php parse error syntax error and there's nothing wrong with the php code AT ALL.

1. Am I misplacing the entire php code on my webpage?

2. Should I place the .js files at the top of the page, and the php script at the top and keep the table that displays the php info half way through the web page? because I need the table with the info in it to be seen in the middle of the webpage.

3. Should the .js files be placed at the top of the page, and the php script above the table where the info will be displayed?
Last edited by inoob on Wed Apr 17, 2013 2:02 pm, edited 1 time in total.
inoob
New php-forum User
New php-forum User
 
Posts: 31
Joined: Tue Nov 06, 2012 12:20 pm

Re: Where to place my php script in my webpage?

Postby seandisanti » Wed Apr 17, 2013 2:02 pm

1) If you're looking for help with specific code, you should post the code.

2) It sounds like you're just throwing in a piece of php into an html page. It's often easier to do the page in php, and have it echo out the php as necessary to generate the page based on the logic.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Where to place my php script in my webpage?

Postby inoob » Wed Apr 17, 2013 2:16 pm

Oh the code works fine as I tested it in another folder in localhost. I don't need help with the script itself. I am placing this script in another .php file. It's not in an html page. Other php scripts in the .php file all compile correctly, while the one I am having issue with is not compiling correctly even though there is nothing wrong with the script at all.

For better understanding, here is a sample:

===================================
Code: Select all
<script type="text/javascript" src="https://ajax.googleapis.com/jquery/1.9.1/jquery.min.js">
<script type="text/javascript" src="script.js"></script>
<?php PHP CODE IS HERE. NO ERRORS AT ALL. ?>
<table>DISPLAY INFO FROM PHP SCRIPT</table>

===================================

I placed this entire script into a spot in the middle of my webpage. The php script is correct even though it still shows a parse error. However, when I placed the PHP script at the top of the webpage, it worked. So why does it work when its at the top and doesnt work when I place it in the middle with the <table> script? The end of the PHP script has mysqli_close($conn);. Should this code be placed at the bottom of the .php page so the script will work in the middle?
inoob
New php-forum User
New php-forum User
 
Posts: 31
Joined: Tue Nov 06, 2012 12:20 pm

Re: Where to place my php script in my webpage?

Postby seandisanti » Wed Apr 17, 2013 3:01 pm

It's impossible to give you specific answers without you providing specific code or even error messages.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Where to place my php script in my webpage?

Postby johnj » Wed Apr 17, 2013 10:03 pm

Usually js code is included in a php file at the beginning but there are exceptions based on requirements. As long as you open and close php code properly using the <?php and ?> tags, you should not get errors.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Where to place my php script in my webpage?

Postby inoob » Fri Apr 19, 2013 4:36 pm

Thanks for the reply guys. I figured out the issue.

There should be a point system here to give points to helpers like experts-exchange.com :)
inoob
New php-forum User
New php-forum User
 
Posts: 31
Joined: Tue Nov 06, 2012 12:20 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.