using array's in PHP

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
vegas89002
New php-forum User
New php-forum User
Posts: 1
Joined: Sat Aug 18, 2018 4:44 pm

Sat Aug 18, 2018 4:58 pm

I'm fairly new to PHP and am making a form for my job. Basically it's just a timesheet with 17 lines of input that repeat themselves as shown below. Basically what I am looking for is the simplest way to process the form via PHP without having to name inputs with different names. For example, WO#, I don't want to have to do WO#1, WO#2, WO#3 and so on 17 times for each input related to the WO# and then have to do the same thing when I write the variables. I know a little about using array's and was wondering how to use a variable like WO#[ ] could benefit me? or if it's even possible? or do I just have alot of repetitive boring typing to do? AND, if it is possible what would I have to do to my mysql tables as well, meaning would I still have to have 17 tables names each with a number or what?
ts.png
ts.png (43.86 KiB) Viewed 112 times

User avatar
benanamen
New php-forum User
New php-forum User
Posts: 54
Joined: Mon Oct 16, 2017 1:06 pm

Sun Aug 19, 2018 9:44 am

Just make the form name an array. Then just loop over the array to insert to DB

<input type="text" name="same_name[]">
<input type="text" name="same_name[]">
<input type="text" name="same_name[]">
<input type="text" name="same_name[]">


You can see an example at my website here: https://galaxyinternet.us/php-insert-form-array/
The XY Problem
The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

Post Reply