close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Submit records in multiple rows not working

Thread began 5/24/2021 5:21 pm by Michael | Last modified 5/27/2021 7:45 pm by Ray Borduin | 59 views | 9 replies |

Michael

Submit records in multiple rows not working

Hello Ray,

Please I kindly need your help on this. I have a form with 3 different array fields prt_id, mds_id and ptid but when I submit the form, only one record in prt_id is submitted and one row only instead of 9 six rows as I selected 3 different options in the 3 dropdown select fields

What am I not doing well looking at my code below:

<?php
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$InsertQuery = new WA_MySQLi_Query($FRCDB);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "verification";
$InsertQuery->bindColumn("prt_id", "i", "".($_POST["prt_id"][$x]) ."", "WA_DEFAULT");
$InsertQuery->bindColumn("mds_id", "i", "".($_POST["mds_id"][$x]) ."", "WA_DEFAULT");
$InsertQuery->bindColumn("aimsobj", "s", "".((isset($_POST["aimsobj"]))?$_POST["aimsobj"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("ptid", "i", "".($_POST["ptid"][$x]) ."", "WA_DEFAULT");
$InsertQuery->bindColumn("phyinspctn", "s", "".((isset($_POST["phyinspctn"]))?$_POST["phyinspctn"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("mdamtng", "s", "".((isset($_POST["mdamtng"]))?$_POST["mdamtng"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("contctmtng", "s", "".((isset($_POST["contctmtng"]))?$_POST["contctmtng"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("consntmtng", "s", "".((isset($_POST["consntmtng"]))?$_POST["consntmtng"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("others", "s", "".((isset($_POST["others"]))?$_POST["others"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("recomnds", "s", "".((isset($_POST["recomnds"]))?$_POST["recomnds"]:"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("addedby", "s", "".((isset($_POST["addedby"]))?$_POST["addedby"]:"") ."", "WA_DEFAULT");
$InsertQuery->saveInSession("pjv_id");
$InsertQuery->execute();
$InsertGoTo = "verification";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
}
?>

Thank you

Sign in to reply to this post

Ray BorduinWebAssist

Your insert redirect is going to cause the page to redirect after the first insert. You would have to remove the redirect to allow all of the inserts to take place. If you want to loop on multiple arrays, you would need multiple FOR loops as well. 3 different options with 3 different options would insert 27 rows if you looped on all 3.

Sign in to reply to this post
Did this help? Tips are appreciated...

Michael

Originally Said By: Ray Borduin
  Your insert redirect is going to cause the page to redirect after the first insert. You would have to remove the redirect to allow all of the inserts to take place. If you want to loop on multiple arrays, you would need multiple FOR loops as well. 3 different options with 3 different options would insert 27 rows if you looped on all 3.  



Thank you so much.

By removing the redirect, it means I will have to remove the *$InsertGoTo = "verification";*

OK let me try it out

Sign in to reply to this post

Michael

Originally Said By: Ray Borduin
  Your insert redirect is going to cause the page to redirect after the first insert. You would have to remove the redirect to allow all of the inserts to take place. If you want to loop on multiple arrays, you would need multiple FOR loops as well. 3 different options with 3 different options would insert 27 rows if you looped on all 3.  



Thank you so much Ray. Your idea worked. I removed the redirect and the records were inserted based on the number of prt_id records. However, that gave me a different route to the project. I changed

$InsertQuery->bindColumn("mds_id", "i", "".($_POST["mds_id"][$x]) ."", "WA_DEFAULT");
$InsertQuery->bindColumn("ptid", "i", "".($_POST["ptid"][$x]) ."", "WA_DEFAULT");

$InsertQuery->bindColumn("mda", "s", "".((isset($_POST["mda"]))?implode(",",$_POST["mda"]):"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("projectteam", "s", "".((isset($_POST["projectteam"]))?implode(",",$_POST["projectteam"]):"") ."", "WA_DEFAULT");

So that the entries will reply on only one multiple row entries which is the prt_id records.

I am so grateful

Sign in to reply to this post

Michael

Originally Said By: Ray Borduin
  Your insert redirect is going to cause the page to redirect after the first insert. You would have to remove the redirect to allow all of the inserts to take place. If you want to loop on multiple arrays, you would need multiple FOR loops as well. 3 different options with 3 different options would insert 27 rows if you looped on all 3.  



2 Things Ray,

1. Please how do I redirect after insertion. My code is without this lines now

$InsertGoTo = "verification";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);

2. I am getting this error "Notice: Undefined index: prt_id in C:\wamp64\www\frcapp\add_project_verification.php on line 46". Please see attached image, how do I resolve it please. I have done my best to remove it but its not going of

Thank you

Sign in to reply to this post

Ray BorduinWebAssist

Please attach the page with the error. I'd want to look at line 46 (and probably the lines above it) to see what is wrong.

Sign in to reply to this post
Did this help? Tips are appreciated...

Michael

Originally Said By: Ray Borduin
  Please attach the page with the error. I'd want to look at line 46 (and probably the lines above it) to see what is wrong.  



Please find attached the file with error on line 46

Sign in to reply to this post

Michael

Originally Said By: Ray Borduin
  Please attach the page with the error. I'd want to look at line 46 (and probably the lines above it) to see what is wrong.  



Hi Ray, please I am still waiting for your response on this. I had earlier sent the page with the error for your viewing.

Thank you

Sign in to reply to this post

Ray BorduinWebAssist

Just add the redirect manually below the insert loop like:

php:
<?php

if ($_SERVER["REQUEST_METHOD"] === "POST") {
  
header("location: redirectpage.php");
  die();
}
Sign in to reply to this post
Did this help? Tips are appreciated...

Michael

Originally Said By: Ray Borduin
  Just add the redirect manually below the insert loop like:
php:
<?php

if ($_SERVER["REQUEST_METHOD"] === "POST") {
  
header("location: redirectpage.php");
  die();
}
  




Thank you sir.

I tried it out and it worked

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...