troubleshooting Question

How to insert Commitment dates for each unit

Avatar of Crazy Horse
Crazy HorseFlag for South Africa asked on
PHP
8 Comments1 Solution55 ViewsLast Modified:
I had this question after viewing Adding additional variables to key => value association.

Hopefully this will be the last piece of the puzzle. I have text fields for each unit where a commitment date must be entered. I am using a foreach loop but when I var_dump it I can see way too many units.

Here is my html table. I am storing the unit key in a hidden field

<tr>
<td>{$thing}</td>
<td>{$row_data}</td>
<td>{$out_xwhen[$thing]}</td>
<td><input type="text" class="form-control" name="commit_date[]" placeholder="Commitment date" id="date"><input type="hidden" name="u_key[]" value="{$thing}"></td>
</tr>

The UPDATE query :

foreach($_POST['commit_date'] as $commitdate) {
$stmt = $link->prepare("UPDATE `units` SET `commit_date` = ? WHERE `u_key` = ?");
$stmt->bind_param("si", $commitdate, $_POST['u_key']);
$stmt->execute();
$stmt->close();

When testing, if I var_dump the commitment date, I get three dates for 3 text fields and the output matches what I inputted. The units however looked like this.

array(3) { [0]=> string(6) "905467" [1]=> string(6) "675483" [2]=> string(6) "501786" } array(3) { [0]=> string(6) "905467" [1]=> string(6) "675483" [2]=> string(6) "501786" } array(3) { [0]=> string(6) "905467" [1]=> string(6) "675483" [2]=> string(6) "501786" }
ASKER CERTIFIED SOLUTION
Crazy Horse

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros