Post Multiple Records to a CSV /...

User 2442557 Photo


Guest
2 posts

Hi all,

I'd love to post this to the main forum for advice, but I guess since I purchased through the Mac App Store I'm outta luck.

Anyway, I'm trying to set up a form using Web Form Builder for people to add lists of their favorite books in a certain category. I want them to be able to list multiple books per category and then have those records go into a single column. For example, the online form would look like:

BOOK...........AUTHOR
[_________] [_________]
[_________] [_________]
[_________] [_________]
[_________] [_________]
[_________] [_________]

So they could enter five books with corresponding authors.

But in the database this would create ten columns... I want it to create just two columns, all books corresponding with their authors.

Does anybody know how to tweak the code to make it do this?

Thanks for any help.
User 2442557 Photo


Guest
2 posts

Here's what I've come up with so far, but I'm getting stuck.

I took the lines in the file datasavemysql.cls.php that read:

$sql = 'INSERT INTO ' . $this->_EscapeName( $this->table . CC_FB_FILEUPLOAD_EXT ) . ' (name, fdata) VALUES (?,?)';
$sth = $this->db->prepare( $sql );


And I changed it to:

$sql = INSERT INTO books (titles, author)
VALUES ('$title1', '$author1')
('$title2', '$author2')
('$title3', '$author3')
('$title4', '$author4')
('$title5', '$author5')
$sth = $this->db->prepare( $sql );


But when I try to submit the form, it throws an error:

Parse error: syntax error, unexpected T_STRING in /php/datasavemysql.cls.php on line 356.

Line 356 is the one that reads $sql = INSERT INTO books (titles, author).

Anyone out there know what newbie mistake I'm making here?

I should mention that the field names are set to book1, book2, etc. and author1, author2, etc.
User 187934 Photo


Senior Advisor
20,266 posts
Online Now

Why do you need it to do that in the database when you can write the php script to extract the data and display it however you like?:) I must not understand where your going with this.:)
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 122279 Photo


Senior Advisor
14,622 posts
Online Now

It's a long time since I've been working with databases that way, but what you need is one column for ID, one for books and one for authors.
Ha en riktig god dag!
Inger, Norway

My work in progress:
Components for Site Designer and the HTML Editor: https://mock-up.coffeecup.com


User 187934 Photo


Senior Advisor
20,266 posts
Online Now

He's looking to submit all the authors and all the books to the same columns at the same time. I'm not sure this is possible as each form element needs it's own identifier name. Maybe prism knows of a script that will loop the submission so each one gets submit after another. It's easy enough to have the five columns for each book and author then use a php script to extract the needed data and display it the way he's looking for.:)
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 464893 Photo


Ambassador
1,611 posts

looking at what you are asking Gus. I could see dozens of Authors and even more book titles. I think an approach would be as Eric was indicating. First input the data and use a script to access the database.

If you do not want to go down the php route consider downloading the csv or exporting the database to Access or a Spreadsheet to do the sorting. Open Office will do it and is free.

If you have a form available it can be populated by anyone and I am sure they will come up with authors you have never heard of and just as many titles.

Consider the logistics, the Genre of the subject or just restrict to a controlled input.
The Guy from OZ



Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.