DTP


 
Lively discussions on the graphic arts and publishing — in print or on the web


Go Back   Desktop Publishing Forum > General Discussions > Web Site Building & Maintenance

Reply
 
Thread Tools Display Modes
Old 10-10-2013, 05:50 AM   #1
jwoolf09
Member
 
Join Date: Oct 2005
Location: Manchester, NH
Posts: 65
Default A repeating form with PHP and Javascript?

I'm working on teaching myself web-programming using PHP and MySql as the back end. Specifically, I'm working on a database to build and display my website dynamically. Since the goal here is to teach myself web-database programming, and the database I need is much too big to edit through something like HeidiSQL, I'm creating a series of webpages to be front end for adding and editing records in the said database.

Right now, I'm looking at the (seemingly) thorny problem of adding lines to a repeating group in a web form. That is, I have a web form that is a series of repeating groups, each group corresponding to 1 row in a table. I want this one form to be able to both edit existing records and add new records. I'd like to be able to add new lines and populate them, then have the whole form saved as a single Submit operation, old lines and new lines at the same time.

In other words, I want to have a form that shows, say, 4 lines:

row 1 --> field1 field2 field3 field4
row 2 --> field1 field2 field3 field4
row 3 --> field1 field2 field3 field4
row 4 --> field1 field2 field3 field4

and buttons for "Add Line" and "Save". The values for fields 1-4 are retrieved via an SQL query from the table and stored as arrays, then the form lines are generated from those arrays using PHP. Clicking "Add Line" adds a new row to the form, while clicking "Save" submits the whole form, old lines and any new lines, to a second PHP script that saves all rows.

I've tried doing this all in Javascript and run aground on the fact that adding a row to the table apparently doesn't add elements to the underlying arrays. So I get errors when I try to save the new line(s). I can't add elements to the arrays using Javascript, because Javascript doesn't seem to know the arrays exist.

I have a distinct feeling that I'm making this harder than it needs to be ... or that I'm trying to do something that can't be done. Is there a way to do what I want within my form, or am I looking at a problem that can be solved only with asynchronous server calls (which I am not ready to try yet) or by calling the same form with different parameters so that the PHP script handles all the details of adding the new blank line?

-- JSW
jwoolf09 is offline   Reply With Quote
Old 10-11-2013, 04:01 AM   #2
Barrie Greed
Member
 
Join Date: May 2006
Location: Stringston, Somerset,UK
Posts: 111
Default

A few thoughts which may or may not be of help.

I am not clear why you want to have a single form for amending records and adding records. Personally I would not mix, on the same form, two separate processes. I would have one web page for amending existing records and one page for entering new records.Once you start writing the data to mysql you will need to split the data between two separate statements anyway. An UPDATE statement to amend the existing records and an INSERT INTO statement to add the new records.

I may be misunderstanding your intentions but your post seems to suggest you were planning to use a single INSERT INTO statement for all the data. I cannot see how that could work. If you have any fields with unique data you will end up with a mysql error. If there is no unique data field you will duplicate the existing records.

Personally I use phpMyAdmin to administer databases. It is far easier. But you may need to set up arrangements for your web site users to update databases in the future so your current exercise will probably be useful in the long run.

If I have completely misunderstood what you are trying to do please post back with some more detail.




Barrie Greed
Barrie Greed is offline   Reply With Quote
Old 10-11-2013, 06:46 AM   #3
jwoolf09
Member
 
Join Date: Oct 2005
Location: Manchester, NH
Posts: 65
Default

Hi Barrie,

Thanks for the response.

Quote:
Originally Posted by Barrie Greed View Post
A few thoughts which may or may not be of help.

I am not clear why you want to have a single form for amending records and adding records.
I'm coming to this from the angle of a PC database programmer. PC database packages routinely have a single 'view data' form with controls for add, edit, and delete.

Quote:
Originally Posted by Barrie Greed View Post
I may be misunderstanding your intentions but your post seems to suggest you were planning to use a single INSERT INTO statement for all the data.
I understand I need separate program code for Add and Update. I determine which one to do by first doing a query for the record's primary key. If the key is found I know I'm doing an update; if not, I know I'm doing an insert.

Quote:
Originally Posted by Barrie Greed View Post
Personally I use phpMyAdmin to administer databases. It is far easier.
This isn't for database administration. This is a purely personal project for entering data into a database -- a lot of it, as fast as possible. My personal website (www.jwoolfden.com) is almost embarrassingly old and is all static HTML. I'm redoing it so that many of the pages will be built from a database. For example, see http://www.jwoolfden.com/ww2_air.html. It's configured in several sections, each of which contains a header paragraph and a list of books. I want to write it so that the primary content - the sections - for the page is read from a database. However, one step in doing that is getting data into that database for the page PHP to read. I already have most of the books stored -- they were in a database long before I even built the old site. I'm now building a second table to hold the Section Headers data. Unfortunately, that data isn't anywhere but in the old pages.

I could simply block-copy from the old pages directly into a database front end, but I'd rather use this as a learning experience, an exercise in building data entry web forms. So I want a form that will show me what sections exist for a given pagename, let me edit existing section records and add new section records. I can do that easily in Foxpro or Access or any other PC database package. I want to learn how to do it on a web form.

Does this make things any clearer?

-- Jon W.
jwoolf09 is offline   Reply With Quote
Old 10-12-2013, 04:46 AM   #4
Barrie Greed
Member
 
Join Date: May 2006
Location: Stringston, Somerset,UK
Posts: 111
Default

Jon

From what you say I get the feeling your database skills are far better than mine. I feel like I'm trying to teach gran how to suck eggs.

For the straightforward task of inserting extra fields have a look at this random snippet. That should achieve your basic aim. Obviously you will need to adjust the counter for the number of rows retrieved from the database.

Emulating an Access or Fox Pro client is beyond my skills. I guess it must be possible as the good folk at Google are able to develop Web Apps that can handle documents being updated by more than one person in real time. But I'm afraid I'm not up to that.

Barrie Greed
Barrie Greed is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
hold the Javascript! john_b Web Site Building & Maintenance 6 02-15-2012 09:17 AM
Eudora 7.1 with Java, JavaScript dthomsen8 Software 14 05-17-2007 02:43 PM
Firefox 1.5 JavaScript Console Kelvyn Web Site Building & Maintenance 0 12-13-2005 12:01 PM
Help with JavaScript coding ilox Web Site Building & Maintenance 15 09-07-2005 01:50 AM


All times are GMT -8. The time now is 03:49 PM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Contents copyright 2004–2014 Desktop Publishing Forum and its members.