The following error appears when I remove this line:
$member_id = (!empty($member_id) ? trim(reset($member_id)) : '');
Notice : Array to string conversion in /var/www/cabgop/record_attn.php on line 177
Fatal error : Uncaught PDOException: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: āā for column cabgop_db
.attendance
.attend_state
at row 1 in /var/www/cabgop/record_attn.php:182 Stack trace: #0 /var/www/cabgop/record_attn.php(182): PDOStatement->execute() #1 {main} thrown in /var/www/cabgop/record_attn.php on line 182
All Iām trying to do is make a popup box that basically says Hey, I see you have a person here, but I already have this guy marked down as absent. Do you want to convert this record and have me mark them as attended instead? with a Yes or No. I already did this when you showed me how to trigger the modal using JS.
Now Iām looking at PHP. If I click Yes, the entire absence record that already exists needs to be deleted because the data is in another table. At the same time, the information I entered in the attendance form needs to be submitted into a second table to make the correction.
Using PHP, I have already defined the query that needs to be processed:
$stmt = $pdo->prepare("INSERT INTO attendance (member_id, member_email,
member_phone, present, attend_state) VALUES (:member_id, :member_email,
:member_phone, :present, :attend_state)");
$stmt->bindParam(':member_id', $member_id);
$stmt->bindParam(':member_email', $member_email);
$stmt->bindParam(':member_phone', $member_phone);
$stmt->bindParam(':present', $present);
$stmt->bindParam(':attend_state', $attend_state);
The data I need is already stored in these variables because the query is called later when a record goes through without issue unless that person has already been marked present in which case the system will stop and prompt me saying This delegate has already been marked present.
try {
$id = $_POST["member_id"];
$ary = explode("-", $id);
$member_id = $ary[0];
$member_email = $_POST["member_email"];
$member_phone = $_POST["member_phone"];
$present = $_POST["present"];
$attend_state = $_POST["attend_state"];
$stmt->execute();
header('Location: record_attn.php');
exit();
} catch(PDOException $e) {
$msg = "This delegate has already been marked present";
}
I donāt think I need to identify the query a second time in the modal since that would be too redundant. So I want to call the original query I defined after the check goes through by running $stmt->execute();
. The problem is the query stops when it hits the checkboxes and Iām not sure why.
The other side of the coin is if I click No, the page needs to reload and a message appears saying This person could not be marked present. Please try again.
To set the message, I define the message (or error) variable at the top of the page (or code) like this:
$msg = "";
Then, I create a place in HTML for the error to be shown like this:
<div class="small">
<p style="text-align: left; font-size: 14px;"><b class="text-danger"><?php echo $msg; ?></b></p>
</div>
If the code fails, messages (or errors) are automatically generated. This one, for instance, where a duplicate record is entered:
} catch(PDOException $e) {
$msg = "This delegate has already been marked present";
}
If a duplicate record is entered, the page will reload itself and that message shows up in red at the top of the page. I need this exact same thing to happen when I click āNoā in my modal. The page should reload first, then the message should appear. But this time, no message shows up?
if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['btn_stop'])):
$msg = "This delegate could not be marked present. Please try again.";
endif;
You are right. This program is my baby and I know exactly what I need to code in order to make it work. What I struggle with is how to code it.