Jump to content
Larry Ullman's Book Forums

Form_Function.Inc.Php, Chapter 4


Recommended Posts

Hi!

 

The idea of storing the logic in a form process is great since it's used over and over again in many (most in my case) projects.

 

What I can't find in the book is an explanation how to use it in a "change case". Let me explain: Let's say I have a script for displaying contacts that are stored in a table in a db.

 

The script display my contacts in my browser in a dynamic table that is based on this mysql table.

 

The contact list only has first_name and last_name to deal with. (Let's keep it simple here)

 

After each post I have a Change botton that passes the posts id back to the script.

The scripts sees the id in the url and creates a sticky form, meaning it displays the posts first_name and last_name from the mysql table.

 

I'd like to change the form_funtion in the book that it suits also this purpose (and only optionaly, since it is used only in this "change scripts")

 

Can anyone give me some thoughts about how to achieve this?

 

Shall I pass the first_name and last_name as some sort of optional arguments?

Link to comment
Share on other sites

I think I see what you're trying to say. You want to have an HTML table of data from a database that's organized, and when you click an "Edit" button next to an entry, another page is loaded with all the corresponding info loaded into a form for editing, right?

 

Assuming that's what you're talking about, Larry addresses that exact thing in his PHP 6 & MySQL 5 book. He has a whole part about editing existing users, and it's pretty much like you're suggesting: Post the ID to a script for editing, which uses that ID to load the proper data into a form, and when the form is submitted all the values are checked for validity and the corresponding database entries are updated.

 

Anyway, muuucho, to fully answer your question, you don't really need to add a function for this, because you'll want to call a separate script, which will handle any ID all the same, and since you only need to write the code once, a function isn't necessary.

 

Does that answer your question?

  • Upvote 1
Link to comment
Share on other sites

Yes, I want to achieve a sticky from like Larry goes through vere nice in PHP6/mysql5 and also in the PHP5 Advanced. However in the Ecom book he is discussing putting the logic in the form process in a separate script so it can be reused several times in different applications.

 

In a project I might have several "change posts" occasions: changing (updating) of posts in various tables that are storing stuffs like clients articles suppliers and so on.

 

What I want to do is making a reusable function for this.

 

In Ecom Larry is showing how to acomplish a reusable fumction for adding new posts to a table via a sticky form. What I try to descibeis the posibilies to achieve the same nice concept when you want to change an existin post.

 

I hope this clarifies what I was trying to say from the start. If not, don't hesitate to ask specificly whats unclear.

 

Best Regards, Muuucho

 

I think I see what you're trying to say. You want to have an HTML table of data from a database that's organized, and when you click an "Edit" button next to an entry, another page is loaded with all the corresponding info loaded into a form for editing, right?

 

Assuming that's what you're talking about, Larry addresses that exact thing in his PHP 6 & MySQL 5 book. He has a whole part about editing existing users, and it's pretty much like you're suggesting: Post the ID to a script for editing, which uses that ID to load the proper data into a form, and when the form is submitted all the values are checked for validity and the corresponding database entries are updated.

 

Anyway, muuucho, to fully answer your question, you don't really need to add a function for this, because you'll want to call a separate script, which will handle any ID all the same, and since you only need to write the code once, a function isn't necessary.

 

Does that answer your question?

Link to comment
Share on other sites

  • 10 months later...

Muucho,

Did you get an answer to your question. I have the exact same question. I have passed the 'article_id' to an edit page but editing the form function is still looming from my grasp. I have three books open; there is a hint on page 73 of ECOMM book value="?php echo $_POST,..

 

pg 272 in php6/MySQL 5 I see using $row from the query,.. all code before this form is what I had come up with. My guess is to drop the form function and just code this page separate? Unless someone has figured out how to adjust the function??? I must sleep on this some but would love some more clues if anyone has any.

 

One other note, I see if(!empty in eccomm book script but in php6 book form uses if (empty...

 

 

thanks

bhb

Link to comment
Share on other sites

 Share

×
×
  • Create New...