0

Nothing I can find anywhere so far answers my problem with this error message which occurs nowhere else on my site nor on this page.

I have two tables: (I've simplified them for brevity)
sasc_mem with fields memberID, fname, lname, join_date, paid
sasc_archive with fields memberID, fname, lname, join_date, retired (date field).

The page is designed to show the membership manager how many members will be moved from one to the other table, and requires that person consciously make the decision to do it.

The code successfully counts and displays the number of unpaid members.

<?php
//define the database connections
require_once(connectvars.php) 

 // Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
 or die('Error connecting to MySQL server.');

echo '<p>You are about to archive <b>';
$sql = 'SELECT COUNT(paid) FROM sasc_mem  WHERE paid ="No"';
$paid = mysqli_query($dbc, $sql);
while($row = mysqli_fetch_array($paid)){
    echo  $row['COUNT(paid)'];}         
echo  '</b> unpaid members from the Membership List.</b><br /><br />';

I'm using INSERT INTO..SELECT FROM to copy the records of unpaid members from one to the other. The sql code to copy rows from sasc_mem to sasc_archive works perfectly within the database so I know it works but the online form results in an error message "Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\sasc\members\admin\membership\bulk_archive.php on line 15.

My database parameters are defined in the connectvars.php file and I have no problem with this anywhere else on the site so I'm missing something obvious but I can't figure out what. I'm hoping other more experienced eyes will be able to identify the problem.

This part generates the error message.

if (isset($_POST['submit'])) {
   if ($_POST['confirm'] == 'Yes')   {

$sql = 'INSERT INTO sasc_archive (memberID, fname, lname,join_date)
       SELECT memberID, fname, lname,join_date
       FROM sasc_mem WHERE paid="No"';
     mysqli_query($dbc,$sql) or die(mysqli_error($db));
   }
}
    echo <<< HTML
<p><b>Select "Yes" before selecting Archive.</b></p>
<form class="gap"  enctype="multipart/form-data" method="post" action="bulk_archive.php">
<input type="radio" name="confirm" value="Yes" /> Yes 
<input type="radio" name="confirm" value="No" checked="checked" /> No 
<input type="submit" name="submit" value="Archive" />     
</form>
HTML;

?>

Bev Horn
  • 9
  • 4

0 Answers0