I have got it to work but am confused with how many closing brackets I need because for my first two queries, I put only 6 closing brackets, where as my last query, I needed 11 closing brackets for it to work. What is the rule of thumb here with the closing brackets?? Can someone check to see if all my closing brackets are correct or not?
<?php
ob_start();
include_once __DIR__.'/header2.php';
if ($_SESSION['u_uid']) {
echo "<meta http-equiv='refresh' content='0;url=header2.php?index=mustloggedoutfirst'>";
exit();
} else {
include_once __DIR__.'/includes/dbh.php';
date_default_timezone_set('Australia/Melbourne');
$date = strip_tags(date('Y-m-d H:i:s'));
$banned = 1;
$student_added = 'Yes';
$activate = 0;
$email_verify = 0;
$email_verify_expiry = null;
$login_attempts = null;
$login_attempts_reminder = 2;
$student_added ='No';
$sql = "SELECT * FROM users;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo 'SQL error';
exit();
} else {
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$resultCheck = mysqli_num_rows($result);
$sql2 = "SELECT * FROM users WHERE ? >= email_verify_expiry;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql2)) {
echo 'SQL error';
exit();
} else {
mysqli_stmt_bind_param($stmt, "s", $date);
mysqli_stmt_execute($stmt);
$result2 = mysqli_stmt_get_result($stmt);
$resultCheck2 = mysqli_num_rows($result2);
$row2 = mysqli_fetch_assoc($result2);
if ($resultCheck2 > 0) {
$sql3 = "UPDATE users
SET email_verify = ?, email_verify_expiry = ?
WHERE user_uid = ?
;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql3)) {
echo 'SQL error';
exit();
} else {
mysqli_stmt_bind_param($stmt, "iss", $email_verify, $email_verify_expiry, $row2['user_uid']);
mysqli_stmt_execute($stmt);
$sql4 = "SELECT * FROM users WHERE user_session >= ?;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql4)) {
echo 'SQL error';
exit();
} else {
mysqli_stmt_bind_param($stmt, "s", $session_expiry);
mysqli_stmt_execute($stmt);
$result4 = mysqli_stmt_get_result($stmt);
$resultCheck4 = mysqli_num_rows($result4);
if ($resultCheck4 > 0) {
$sql5 = "DELETE FROM users WHERE user_uid = ? AND user_email = ?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql5)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "ss", $row2['user_uid'], $row2['user_email']);
mysqli_stmt_execute($stmt);
$sql6 = "DELETE FROM memberships WHERE user_uid = ? AND user_email = ?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql6)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "ss", $row2['user_uid'], $row2['user_email']);
mysqli_stmt_execute($stmt);
$sql7 = "DELETE FROM customer_lessonfees WHERE user_uid = ? AND user_email = ?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql7)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "ss", $row2['user_uid'], $row2['user_email']);
mysqli_stmt_execute($stmt);
$sql8 = "DELETE FROM rewards WHERE user_uid = ? AND user_email = ?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql8)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "ss", $row2['user_uid'], $row2['user_email']);
mysqli_stmt_execute($stmt);
$sql9 = "DELETE FROM student_details WHERE user_uid = ? AND user_email = ?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql9)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "ss", $row2['user_uid'], $row2['user_email']);
mysqli_stmt_execute($stmt);
// Edit this path if PHPMailer is in a different location.
//$mail->SMTPDebug = 2;
include_once __DIR__.'/PHPMailer/Exception.php';
include_once __DIR__.'/PHPMailer/PHPMailer.php';
include_once __DIR__.'/PHPMailer/SMTP.php';
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->CharSet = 'UTF-8';
//$mail->isSMTP(); enable this for localhost and disable for live host???
$mail->isHTML(true);
/*
* Server Configuration
*/
$mail->Host = 'smtp.gmail.com'; // Which SMTP server to use.
$mail->Port = 587; // Which port to use, 587 is the default port for TLS and 465 for SSL security.
$mail->SMTPSecure = 'tls'; // Which security method to use. TLS is most secure.
$mail->SMTPAuth = true; // Whether you need to login. This is almost always required.
$mail->Username = "[email protected]"; // Your Gmail address.
$mail->Password = "*******"; // Your Gmail login password or App Specific Password.
/*
* Message Configuration
*/
$mail->setFrom('[email protected]', 'PianoCourse101 Account Deleted'); // Set the sender of the message.
$mail->addAddress($row2['user_email'], 'PianoCourse101 Account Deleted'); // Set the recipient of the message.
$mail->Subject = 'PianoCourse101 Account Deleted'; // The subject of the message.
/*
* Message Content - Choose simple text or HTML email
*/
// Choose to send either a simple text email...
$mail->Body = "Dear ".$row2['user_first']." ".$row2['user_last'].", <br /></br />
You have received this e-mail because your Primer Level Account has been deleted. You have not login for more than 1 month.
<br /><br />
From,
<br /><br />
PianoCourse101
"; // Set a plain text body.
// ... or send an email with HTML.
//$mail->msgHTML(file_get_contents('contents.html'));
// Optional when using HTML: Set an alternative plain text message for email clients who prefer that.
//$mail->AltBody = 'This is a plain-text message body';
// Optional: attach a file
$mail->addAttachment('images/phpmailer_mini.png');
if ($mail->send()) {
// echo "<meta http-equiv='refresh' content='0;url=index.php?delete_request=success'>";
// exit();
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
}
}
}
}
}else {
$sql10 = "SELECT * FROM users WHERE email_verify = ?;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql10)) {
echo 'SQL error';
exit();
} else {
mysqli_stmt_bind_param($stmt, "i", $email_verify);
mysqli_stmt_execute($stmt);
$result10 = mysqli_stmt_get_result($stmt);
$resultCheck10 = mysqli_num_rows($result10);
$row10 = mysqli_fetch_assoc($result10);
if ($resultCheck10 > 0) {
$sql11 = "DELETE FROM users WHERE user_uid = ? AND user_email = ?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql11)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "ss", $row10['user_uid'], $row10['user_email']);
mysqli_stmt_execute($stmt);
$sql12 = "DELETE FROM memberships WHERE user_uid = ? AND user_email = ?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql12)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "ss", $row10['user_uid'], $row10['user_email']);
mysqli_stmt_execute($stmt);
$sql13 = "DELETE FROM customer_lessonfees WHERE user_uid = ? AND user_email = ?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql13)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "ss", $row10['user_uid'], $row10['user_email']);
mysqli_stmt_execute($stmt);
$sql14 = "DELETE FROM rewards WHERE user_uid = ? AND user_email = ?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql14)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "ss", $row10['user_uid'], $row10['user_email']);
mysqli_stmt_execute($stmt);
$sql15 = "DELETE FROM student_details WHERE user_uid = ? AND user_email = ?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql15)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "ss", $row10['user_uid'], $row10['user_email']);
mysqli_stmt_execute($stmt);
// Edit this path if PHPMailer is in a different location.
//$mail->SMTPDebug = 2;
include_once __DIR__.'/PHPMailer/Exception.php';
include_once __DIR__.'/PHPMailer/PHPMailer.php';
include_once __DIR__.'/PHPMailer/SMTP.php';
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->CharSet = 'UTF-8';
//$mail->isSMTP(); enable this for localhost and disable for live host???
$mail->isHTML(true);
/*
* Server Configuration
*/
$mail->Host = 'smtp.gmail.com'; // Which SMTP server to use.
$mail->Port = 587; // Which port to use, 587 is the default port for TLS and 465 for SSL security.
$mail->SMTPSecure = 'tls'; // Which security method to use. TLS is most secure.
$mail->SMTPAuth = true; // Whether you need to login. This is almost always required.
$mail->Username = "[email protected]"; // Your Gmail address.
$mail->Password = "*******"; // Your Gmail login password or App Specific Password.
/*
* Message Configuration
*/
$mail->setFrom('[email protected]', 'PianoCourse101 Account Deleted'); // Set the sender of the message.
$mail->addAddress($row2['user_email'], 'PianoCourse101 Account Deleted'); // Set the recipient of the message.
$mail->Subject = 'PianoCourse101 Account Deleted'; // The subject of the message.
/*
* Message Content - Choose simple text or HTML email
*/
// Choose to send either a simple text email...
$mail->Body = "Dear ".$row2['user_first']." ".$row2['user_last'].", <br /></br />
You have received this e-mail because your Primer Level Account has been deleted. You have not verified your e-mail account within 24 hours by activating your account.
<br /><br />
From,
<br /><br />
PianoCourse101
"; // Set a plain text body.
// ... or send an email with HTML.
//$mail->msgHTML(file_get_contents('contents.html'));
// Optional when using HTML: Set an alternative plain text message for email clients who prefer that.
//$mail->AltBody = 'This is a plain-text message body';
// Optional: attach a file
$mail->addAttachment('images/phpmailer_mini.png');
if ($mail->send()) {
// echo "<meta http-equiv='refresh' content='0;url=index.php?delete_request=success'>";
// exit();
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
}
}
}
}
}
}
}
}
}
}else {
$sql16 = "SELECT * FROM users WHERE student_added IS NULL;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql16)) {
echo "SQL error";
} else {
mysqli_stmt_execute($stmt);
$result16 = mysqli_stmt_get_result($stmt);
$resultCheck16 = mysqli_num_rows($result16);
echo $resultCheck16;
$row16 = mysqli_fetch_assoc($result16);
if ($resultCheck16 > 0) {
// Edit this path if PHPMailer is in a different location.
//$mail->SMTPDebug = 2;
include_once __DIR__.'/PHPMailer/Exception.php';
include_once __DIR__.'/PHPMailer/PHPMailer.php';
include_once __DIR__.'/PHPMailer/SMTP.php';
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->CharSet = 'UTF-8';
//$mail->isSMTP(); enable this for localhost and disable for live host???
$mail->isHTML(true);
/*
* Server Configuration
*/
$mail->Host = 'smtp.gmail.com'; // Which SMTP server to use.
$mail->Port = 587; // Which port to use, 587 is the default port for TLS and 465 for SSL security.
$mail->SMTPSecure = 'tls'; // Which security method to use. TLS is most secure.
$mail->SMTPAuth = true; // Whether you need to login. This is almost always required.
$mail->Username = "[email protected]"; // Your Gmail address.
$mail->Password = "*******"; // Your Gmail login password or App Specific Password.
/*
* Message Configuration
*/
$mail->setFrom('[email protected]', 'PianoCourse101 Add Student Reminder'); // Set the sender of the message.
$mail->addAddress($row16['user_email'], 'PianoCourse101 Add Student Reminder'); // Set the recipient of the message.
$mail->Subject = 'PianoCourse101 Add Student Reminder'; // The subject of the message.
/*
* Message Content - Choose simple text or HTML email
*/
// Choose to send either a simple text email...
$mail->Body = "Dear ".$row16['user_first']." ".$row16['user_last'].", <br /></br />
You have received this e-mail because you have not added at least one student yet!
<br /><br />
In order to use PianoCourse101, you must at least add one student so that you can use your practice diary.
<br /><br />
From,
<br /><br />
PianoCourse101
"; // Set a plain text body.
// ... or send an email with HTML.
//$mail->msgHTML(file_get_contents('contents.html'));
// Optional when using HTML: Set an alternative plain text message for email clients who prefer that.
//$mail->AltBody = 'This is a plain-text message body';
// Optional: attach a file
$mail->addAttachment('images/phpmailer_mini.png');
if ($mail->send()) {
// echo "<meta http-equiv='refresh' content='0;url=index.php?delete_request=success'>";
// exit();
} else {
echo "Mailer Error: " . $mail->ErrorInfo;
}
}
}
}
}
}
}
ob_end_flush();
?>