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

Insert Multiple Record Issue

Thread began 11/19/2020 10:38 am by anonymous | Last modified 11/19/2020 11:50 am by Ray Borduin | 40 views | 2 replies |

anonymous

Insert Multiple Record Issue

I have the form that queries the database and makes a copy of all the records in the query and then inserts them into the database as a new record. For some reason, I can't get the page to work and I see no error message. Any thoughts?

Here is the code:
<?php
$rollover_year = $_GET['rollover_year'];
if (isset($_POST["submit"]) || isset($_POST["submit_x"])) {
$InsertQuery = new WA_MySQLi_Query($course_catalog);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "courses";
$InsertQuery->bindColumn("course_number", "s", "".((isset($_POST["course_number"]))?implode(", ",$_POST["course_number"]):"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("course_title", "s", "".((isset($_POST["course_title"]))?implode(", ",$_POST["course_title"]):"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("stateID", "s", "".((isset($_POST["stateID"]))?implode(", ",$_POST["stateID"]):"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("departmentID", "i", "".((isset($_POST["departmentID"]))?implode(", ",$_POST["departmentID"]):"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("status", "s", "".((isset($_POST["status"]))?implode(", ",$_POST["status"]):"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("description", "s", "".((isset($_POST["description"]))?implode(", ",$_POST["description"]):"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("notes", "s", "".((isset($_POST["notes"]))?implode(", ",$_POST["notes"]):"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("core_elective", "s", "".((isset($_POST["core_elective"]))?implode(", ",$_POST["core_elective"]):"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("year", "s", "".((isset($_POST["year"]))?implode(", ",$_POST["year"]):"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("subcategory", "s", "".((isset($_POST["subcategory"]))?implode(", ",$_POST["subcategory"]):"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("grade_level", "s", "".((isset($_POST["grade_level"]))?implode(", ",$_POST["grade_level"]):"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("pre_reqs", "s", "".((isset($_POST["pre_reqs"]))?implode(", ",$_POST["pre_reqs"]):"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("credit_assignment", "s", "".((isset($_POST["credit_assignment"]))?implode(", ",$_POST["credit_assignment"]):"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("course_designation", "s", "".((isset($_POST["course_designation"]))?implode(", ",$_POST["course_designation"]):"") ."", "WA_DEFAULT");
$InsertQuery->bindColumn("modified_date", "t", "".((isset($_POST["modified_date"]))?implode(", ",$_POST["modified_date"]):"") ."", "WA_DEFAULT");
$InsertQuery->saveInSession("");
$InsertQuery->execute();
$InsertGoTo = "home.php";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
}
?>

<form id="form1" name="form1" method="post">
<?php
$wa_startindex = 0;
while(!$rollover_selection->atEnd()) {
$wa_startindex = $rollover_selection->Index;
?>
<input type="hidden" name="status[]" id="status" value="Proposed">
<input type="hidden" name="course_number[]" id="course_number" value="<?php echo($rollover_selection->getColumnVal("course_number")); ?>">
<input type="hidden" name="description[]" id="description" value="<?php echo($rollover_selection->getColumnVal("description")); ?>">
<input type="hidden" name="departmentID[]" id="departmentID" value="<?php echo($rollover_selection->getColumnVal("departmentID")); ?>">
<input type="hidden" name="stateID[]" id="stateID" value="<?php echo($rollover_selection->getColumnVal("stateID")); ?>">
<input type="hidden" name="course_designation[]" id="course_designation" value="<?php echo($rollover_selection->getColumnVal("course_designation")); ?>">
<input type="hidden" name="course_title[]" id="course_title" value="<?php echo($rollover_selection->getColumnVal("course_title")); ?>">
<input type="hidden" name="credit_assignment[]" id="credit_assignment" value="<?php echo($rollover_selection->getColumnVal("credit_assignment")); ?>">
<input type="hidden" name="grade_level[]" id="grade_level" value="<?php echo($rollover_selection->getColumnVal("grade_level")); ?>">
<input type="hidden" name="pre_reqs[]" id="pre_reqs" value="<?php echo($rollover_selection->getColumnVal("pre_reqs")); ?>">
<input type="hidden" name="subcategory[]" id="subcategory" value="<?php echo($rollover_selection->getColumnVal("subcategory")); ?>">
<input type="hidden" name="core_elective[]" id="core_elective" value="<?php echo($rollover_selection->getColumnVal("core_elective")); ?>">
<input type="hidden" name="year[]" id="year" value="<?php echo $_GET['rollover_year']; ?>">
<input type="hidden" name="modified_date[]" id="modified_date" value="<?php echo($rollover_selection->getColumnVal("modified_date")); ?>">
<input type="hidden" name="notes[]" id="notes" value="<?php echo($rollover_selection->getColumnVal("notes")); ?>">
<?php
$rollover_selection->moveNext();
}
$rollover_selection->moveFirst(); //return RS to first record
unset($wa_startindex);
unset($wa_repeatcount);
?>
<br><button type="submit" class="btn-lg btn-info" name="submit" id="submit">Yes, Rollover Now!</button>
</form>

Sign in to reply to this post

Ray BorduinWebAssist

Please attach the page when asking for help so I can open it in Dreamweaver and see it in context. I don't think this is the correct technique for this result. There are a variety of issues I can see, but I'd rather suggest a different approach.

You might consider using the "Execute Query" server behavior instead of the recordset and insert and hidden fields. All of this complexity can be avoided.

Just execute a query like:

php:
<?php

if (isset($_POST["submit"]) || isset($_POST["submit_x"])) {
  
$ExecuteQuery = new WA_MySQLi_Query($vpleaguedb);
  
$ExecuteQuery->Statement "INSERT INTO courses (course_number, course_title, stateID, departmentID, `status`, description, notes, core_elective, `year`, subcategory, grade_level, pre_reqs, credit_assignment) (SELECT course_number, course_title, stateID, departmentID, 'Proposed' AS `status`, description, notes, core_elective, ? AS `year`, subcategory, grade_level, pre_reqs, credit_assignment FROM courses WHERE **your current rollover_selection filter**";
  
$ExecuteQuery->bindParam("i""".($_GET['rollover_year'])  ."""-1"); //yearparam
  
$ExecuteQuery->execute();
  
$ExecuteGoTo "home.php";
  if (
function_exists("rel2abs")) $ExecuteGoTo $ExecuteGoTo?rel2abs($ExecuteGoTo,dirname(__FILE__)):"";
  
$ExecuteQuery->redirect($ExecuteGoTo);
}
?>



Then you can remove the insert, recordset, and hidden form elements on your page.

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

anonymous

Thank you so much! This worked perfectly! Your awesome!

Sign in to reply to this post

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...