Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

naive question for categories.php


xvoyance

Recommended Posts

My understanding for such dynamic HTML is that

there is a HTML program at the user side to send a form data,

and a PHP program at the server side to receive data and process.

However, OSC seems to use the same program categories.php

to handle both side.

What is wrong with my understanding?

Link to comment
Share on other sites

@@xvoyance

 

There are two sides to osCommerce, the admin side and the catalog side. When you create a new category (categories.php) from the admin side, it is stored in the database. On the catalog side, the categories.php file simply reads the database and displays the information.

 

Also, to clarify again. osCommerce is PHP, not HTML.

 

 

Chris

Link to comment
Share on other sites

@@xvoyance

 

There are two sides to osCommerce, the admin side and the catalog side. When you create a new category (categories.php) from the admin side, it is stored in the database. On the catalog side, the categories.php file simply reads the database and displays the information.

 

Also, to clarify again. osCommerce is PHP, not HTML.

 

 

Chris

 

NO..No, you misunderstood what I mean.

I am talking about the administrator side only.

The categories.php generated .html file so that we can fill and upload the products.

But which program is on the sever side to received the data?

It is still the same categories.php

Link to comment
Share on other sites

It is still the same categories.php

 

Yes.

 

You need to understand that PHP and HTML are not different and yet they are different.

 

PHP takes data and does things to it.

HTML takes data and does things to it.

 

In general;

 

PHP processes data.

HTML displays data.

Link to comment
Share on other sites

NO..No, you misunderstood what I mean.

your 'understanding' about 'php & html' is either flaw or non-existent. RE that particular question, the cetagories.php is always on the server, not on your pc. so its the same file that does all the work.

 

Ken

commercial support - unProtected channel, not to be confused with the forum with same name - open to everyone who need some professional help: either PM/email me, or go to my website (URL can be found in my profile).

over 20 years of computer programming experience.

Link to comment
Share on other sites

It is very common to write PHP code that generates an HTML form to be filled in on the browser. The same PHP file can detect that it's being sent back form data and will process that data (or detect that there is no form data and it's being asked to send the form to the browser in the first place). This is PHP 101 -- very basic stuff.

Link to comment
Share on other sites

It is very common to write PHP code that generates an HTML form to be filled in on the browser. The same PHP file can detect that it's being sent back form data and will process that data (or detect that there is no form data and it's being asked to send the form to the browser in the first place). This is PHP 101 -- very basic stuff.

 

Could you please give me a SIMPLE example. I tried to find one from book, but not.

I know it should be very simple.

Thanks.

 

p.s.I am an experienced programmer in other languages. But new in PHP etc. OSC is too complicate.

There are indeed some holes in my knowledge. Please help me to fill it. Thanks.

Link to comment
Share on other sites

I found this on the internet and it may help you.

 

PHP files are just like HTML files, but they can include both HTML and PHP code. The PHP code is parsed (or executed) by the Web server when the page is accessed and the resulting output is written as HTML within the Web page. When a user accesses a PHP page, his Web browser only gets sent the HTML code, since the Web server has processed the PHP code in the background. Most PHP pages are processed so quickly that it does not noticeably slow down the loading of the Web page.

 

The .php extension is important, since it tells the Web server that the page may include PHP code. Therefore, it must be run through the server's PHP engine before being sent to a client's Web browser. This allows dynamic content to be generated each time the Web page is loaded, based on the variables included in the PHP code. For example, PHP pages may load objects such as the current date and time, data from form fields submitted by a user, or information from a database. Still, once the page reaches the user's Web browser, everything is formatted as HTML.

REMEMBER BACKUP, BACKUP AND BACKUP

Link to comment
Share on other sites

I found this on the internet and it may help you.

 

PHP files are just like HTML files, but they can include both HTML and PHP code. The PHP code is parsed (or executed) by the Web server when the page is accessed and the resulting output is written as HTML within the Web page. When a user accesses a PHP page, his Web browser only gets sent the HTML code, since the Web server has processed the PHP code in the background. Most PHP pages are processed so quickly that it does not noticeably slow down the loading of the Web page.

 

The .php extension is important, since it tells the Web server that the page may include PHP code. Therefore, it must be run through the server's PHP engine before being sent to a client's Web browser. This allows dynamic content to be generated each time the Web page is loaded, based on the variables included in the PHP code. For example, PHP pages may load objects such as the current date and time, data from form fields submitted by a user, or information from a database. Still, once the page reaches the user's Web browser, everything is formatted as HTML.

 

Yes, I understood all these. What I don't understand is why the same PHP code can be used to generate the HTML but

also act as receiver for the data send from the client to the server. I thought they should be two PHP programs.

 

Could you please give me a simple example. Thanks.

Link to comment
Share on other sites

if (isset($_POST['field1']) {
 // this is a form data submission
 ... do something with $_POST['field1']...
} else {
 // put up the form
 echo '.... rest of page ...
 <form ... action="....php" method="post"... >
 <input type="text" name="field1" .../>
 ... more of form...
 </form>
 ... more of page ...';
}

Link to comment
Share on other sites

if (isset($_POST['field1']) {
 // this is a form data submission
 ... do something with $_POST['field1']...
} else {
 // put up the form
 echo '.... rest of page ...
 <form ... action="....php" method="post"... >
 <input type="text" name="field1" .../>
 ... more of form...
 </form>
 ... more of page ...';
}

 

Yes, this is exactly what I perceived for the categories.php of OSC. But will it work? So, the crucial part is the isset($_POST)?

 

PHP first processed this file and generated a HTML code. At the time it generate the HTML, the isset($_POST)...

part do nothing? At this time the PHP processing should be finished. When the form submitted, isset($_POST) part works, so does the HTML part. So, the HTML will be reloaded, and this PHP program will actually be evoked twice?

 

So, this program could also be separated into two programs?

Link to comment
Share on other sites

Yes, this is exactly what I perceived for the categories.php of OSC. But will it work? Yes So, the crucial part is the isset($_POST)? Yes

 

PHP first processed this file and generated a HTML code. At the time it generate the HTML, the isset($_POST)...

part do nothing? Yes At this time the PHP processing should be finished. When the form submitted, isset($_POST) part works, so does the HTML part No, the HTML output is skipped. So, the HTML will be reloaded No, and this PHP program will actually be evoked twice? Yes, first time to generate the HTML page, and second time to process the form data.

 

So, this program could also be separated into two programs? Yes, but it's usually more convenient to do it in one, especially if you want to error check and put the form back up pre-filled with the entries that were OK. That's a very common thing to do. While processing the form data, you set a flag that there were errors, and then you put up the form again if the flag was set (obviously some minor changes are needed for the control flow).

 

The best thing for you to do is build a simple form with a few fields, and play with it to see how it works.

Link to comment
Share on other sites

Why would you want 2 files? PHP and HTML are the same thing.

 

PHP takes data and does things to it.

HTML takes data and does things to it.

 

I do not understand why you are hung up on this?

Link to comment
Share on other sites

Is there any good reason why experienced programmer want to put those two functions in one file?

They can actually be two separated files.

 

It's easier to keep them in sync if they're in one file (the form generation and the form data processing). Also, as I mentioned, it's common to want to redisplay the form if there is invalid data, so with two files you would just end up having two copies of the form generation (which inevitably will get out of sync!).

 

Sure, go ahead and split into two separate files, but you're just making far more work for yourself, and setting the stage for hard-to-find bugs. Good, experienced programmers will put them into one file. It's normal practice. If you're so hung up on this, go ahead. I'm not going to argue about it any more.

Link to comment
Share on other sites

i can imaging one day someone will ask ro complain that why we human being has only one head? we should have a bunch of heads sticking out from the neck, one with mouth for shouting, one with ear for hearing, etc. seriously, it may happen one day... as already seen similar things...would that be more logical and better??? :)

 

Ken

commercial support - unProtected channel, not to be confused with the forum with same name - open to everyone who need some professional help: either PM/email me, or go to my website (URL can be found in my profile).

over 20 years of computer programming experience.

Link to comment
Share on other sites

Why would you want 2 files? PHP and HTML are the same thing.

 

I do not understand why you are hung up on this?

 

It is out of my intuition.

 

They are doing two different tasks.

Link to comment
Share on other sites

My understanding for such dynamic HTML is that

there is a HTML program at the user side to send a form data,

and a PHP program at the server side to receive data and process.

However, OSC seems to use the same program categories.php

to handle both side.

What is wrong with my understanding?

No, that's not how it works. You may be thinking of jquery, which does work that way. In order for oscommerce to do what it needs to do - like allowing customers to sign up and place orders and you to add products - it has to connect to the mysql database on the server. HTML code doesn't have the ability to talk to a database so it cannot be used to accomplish those things, thus php is used. When the code in the shop is ran, it makes a direct connection to the database before anything else is allowed to happen. So when a customer creates a new account, the php code in the files adds that data to the database, which is open and waiting. If HTML code could be used to talk to the database, then just it could be used. But since it is not written to allow that, php has to be used. Likewise, php doesn't have any fomatting code. Browsers only understand HTML code for formatting the page (for the purposes of this explanation) so HTML has to be used in the file to format the page correctly.

 

They both have to be used in a shop that uses a mysql database - one for handling the data and one for displaying it properly on the page.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

it has nothing related to my question.

 

You asked the difference between PHP and HTML. That script shows you the difference.

 

I can foresee that you will attempt to separate categories into two files, then come running

here for help when it all goes wrong...

Link to comment
Share on other sites

I have found reading these posts quite funny. Why are you trying to reinvent the wheel? If something isnt broken you dont fix it.

 

I am trying to modify it, and I have modified a lot.

Now, I have a book store, which the owner only need to enter the ISBN and the price, the system will automatically get other information form the libraries. The book store can have 1000000 books, such amount of products is difficult to insert with easy-populate.....and I am trying to let the book store have an automatic crawler like google etc which will automatically

get book information elsewhere as far as the book is exists in the universe. ...thanks for those replied, I appreciate your discussion.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...