PHP Questions

Includes, brief code inserts, and snippets. Learning to incorporate server side includes into your code.

Moderators: BobCP, agsone, Neil Parks, gregtutor, Lem3

PHP Questions

Postby casaerwin on Wed Jul 14, 2010 5:18 pm

I'm trying to build a makeshift shopping cart which I will eventually upload to PayPal for payment processing (the real shopping cart). There are several selection lists below each item so the prospective buyer can select various options. Several of these options have prices which are added together to obtain the total price of the item.

So my main question is if I have two forms on the same page, each with a separate action=xxxxxx.php, can the first PHP script access variables in the second form? I want the first PHP script to calculate the total price of the item and set values in the second form which will ultimately be uploaded by a script which resides on PayPal's site.
Dale Erwin
Lurigancho-Chosica, Lima, Peru
http://leather.casaerwin.org
casaerwin
 
Posts: 46
Joined: Mon Jun 21, 2010 8:34 pm
Country: United States (us)

Re: PHP Questions

Postby Lem3 on Wed Jul 14, 2010 6:27 pm

You could have your user make all the selection choices, submit the form, use a server php script to do the math and re-display the entire page with totals added to the second form.

Since all your prices will be contained in the first form, I'd suggest using the selection field "onchange" event to trigger a Javascript function which does the math and modifies the second form right there in the browser.
Lem3
Moderator
 
Posts: 273
Joined: Sun Jun 22, 2008 3:39 pm
Location: Texas

PHP Questions

Postby Tek2007 on Thu Feb 06, 2014 2:04 am

Hey Guys, so I'm taking my first baby steps into the world of PHP and need a little help.

I have a PHP script that includes a web page template, default_template.php. Now although this page is a web page, Komposer doesn't recognise the file as such, my PC has decided that it opens with a photo editing programme (which of course it doesn't). I can open and edit it with Komposer but there is no option to then save as a .php file. However I can save it as "all files" template.php but Komposer still doesn't recognise it.

I tried uploading the template.php with a link from another page but it didn't work, it seemed as if it was looking for a .html file?

So what I don't understand is, if the template page needs to stay as a .php file, how do I link it from a normal menu link? I also don't really understand is if the template page has to stay as.php can all of the other pages on the site be .html?

Any advice will be gratefully recieved.

Cheers
Tek
Tek2007
 
Posts: 38
Joined: Mon Oct 29, 2007 7:58 pm

Re: PHP Questions

Postby wink0r on Thu Feb 06, 2014 4:25 am

The .php extension tells the server to run the page through the php parser where the php code is executed before handing it off to the browser. So yes, if the page contains php code it needs to have the .php extension.

In order to see a file with a php extension in KompoZer you do have to select 'all files' in the file type box. KompoZer will open the files and there will be a yellow rectangle inscribed with PHP as a marker where there is php code. You will have to remember to add the .php extension on first save of the page.

If you are using KompoZer 0.7.10 you should have the handcoder extension for KompoZer installed. (http://fabiwan.kenobi.free.fr/HandCoder/) It generally helps to place a php comment on the first line of the page before the doc type. <?php //PHP made with KompoZer ?> is what I generally use except when the script actually requires a line at the top of the page. Without the comment KompoZer tends to add some meaningless junk in the head section with each save of the page.

agsone has some information about using php includes at: http://agsone.100webcustomers.com/phpinclude.php

Linking does require the correct file name, so the .php extension would be needed if linking to a .php file.

BlueGriffon, a new project by the original lead developer of NVu, does handle php better than KompoZer although you still need to select 'all files' in the file type box.
wink0r
 
Posts: 2583
Joined: Tue Aug 28, 2007 10:10 pm
Location: East Coast - USA
Country: United States (us)

Re: PHP Questions

Postby Tek2007 on Thu Feb 06, 2014 4:53 am

Hi Wink0r and thanks for the quick reply/lesson in php.

I've just now installed the handcoder and set the php files to open in Komoser.

I'm going to check out agsone's page now, looks like I have a bit of reading to do.

Thanks again
Tek
Tek2007
 
Posts: 38
Joined: Mon Oct 29, 2007 7:58 pm

Re: PHP Questions

Postby Tek2007 on Thu Feb 06, 2014 6:45 am

Just a quick one:

As I've already made the rest of the site .html, is it ok to leave them as is and just have the one page .php?

Cheers
Tek
Tek2007
 
Posts: 38
Joined: Mon Oct 29, 2007 7:58 pm

Re: PHP Questions

Postby wink0r on Thu Feb 06, 2014 7:32 am

As long as the script is only used on the one page and there is no php used on the other pages it should not be a problem. I use includes for nav files and some other things, so all of my pages carry the php extension.
wink0r
 
Posts: 2583
Joined: Tue Aug 28, 2007 10:10 pm
Location: East Coast - USA
Country: United States (us)

Re: PHP Questions

Postby Tek2007 on Thu Feb 06, 2014 8:54 am

Cheers for that. Well now I've dipped my toes into the warm seas of php, perhaps I might start to use it some more.
Would it make any difference if I just used .php for all of my pages just in-case I decided to put some code in later?
Tek2007
 
Posts: 38
Joined: Mon Oct 29, 2007 7:58 pm

Re: PHP Questions

Postby wink0r on Thu Feb 06, 2014 9:10 am

That should not be a problem with most servers. Some servers are set to hold the php parser in memory and with others it is probably an option. That saves loading the parser from the disk each time there is a php page to serve.

The bonus to using the php extension now is that if there should be external .html links and you need to change an extension to php you would need to do a redirect to the page. If you use the php extension initially there will be no possibility of broken links due to a change of extension.
wink0r
 
Posts: 2583
Joined: Tue Aug 28, 2007 10:10 pm
Location: East Coast - USA
Country: United States (us)

Re: PHP Questions

Postby Tek2007 on Thu Feb 06, 2014 10:30 am

Are you saying then I'd use less bandwidth if my pages are .php?

So it sounds like it's best just to save everything as .php then, no downsides?
Tek2007
 
Posts: 38
Joined: Mon Oct 29, 2007 7:58 pm

Re: PHP Questions

Postby wink0r on Thu Feb 06, 2014 5:36 pm

The bandwidth would be the same because php works on the server. Basically php fills in the blanks on a web page before the server hands it off to the browser. The browser sees a full html page just as if it were a static page with no dynamic content.

There is a slight possibility that a page might take a bit longer to load (in micro-seconds) if it must go through the php parser (an extra step) before it is served.

Most of the major CMS software is programmed in php. I have some WordPress blogs. The theme that I use gives the time on the server to serve the page in an info box below the page. Usually that is on the order of 200 milliseconds. A WordPress page is almost completely built from dynamic content.
wink0r
 
Posts: 2583
Joined: Tue Aug 28, 2007 10:10 pm
Location: East Coast - USA
Country: United States (us)

Re: PHP Questions

Postby Tek2007 on Thu Feb 06, 2014 11:57 pm

Thanks for the explanation. I'm going to go ahead and make the site I'm currently working on in .php, it's another steep learning curve for me, having had no formal or informal training in web design. I've been reading agsone's page on php and will give it a go having my menu as he's suggested.

I just wanted to say that you guys here really are great, it was solely down to the people on this forum that I was able to make the transition of tables to css, so once again BIG THANKS to you all.

Cheers
Tek
Tek2007
 
Posts: 38
Joined: Mon Oct 29, 2007 7:58 pm


Return to General - PHP/SSI Q&A


Who is online

Users browsing this forum: No registered users and 0 guests