HI everyone,
This is my first post and I will try to be clear as possible.
I would like to make the code enter the information to be a membership and I also want to make the reminder expired date to renew the membership time. I want to ask them to send auto email to them.
this is the code
<?php
$currentDate = date('Y-m-d');
$id = $_POST['student-id'];
$first = $_POST['first-name'];
$last = $_POST['last-name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$date = $_POST['expired'];
if (!empty($id) || !empty($first) || !empty($last) || !empty($email) || !empty($phone) ||
!empty($message) || !empty($date)) {
$host = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbname = "student";
//create connection
$conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);
if (mysqli_connect_error()) {
die('Connect Error('. mysqli_connect_errno().')'. mysqli_connect_error());
} else {
$SELECT = "SELECT email From register Where email = ? Limit 1";
$INSERT = "INSERT Into register (studentid, firstname, lastname, email, phone, message, expireddate) values(?, ?, ?, ?, ?, ?, ?)";
$remind_query1 = "SELECT * FROM register WHERE expireddate= '$currentDate'";
//Prepare statement
$stmt = $conn->prepare($SELECT);
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($email);
$stmt->store_result();
$rnum = $stmt->num_rows;
if ($rnum==0) {
$stmt->close();
$stmt = $conn->prepare($INSERT);
$stmt->bind_param("sssssis", $id, $first, $last, $email, $phone, $message, $date);
$stmt->execute();
//Prepare statement
if($run1 = $conn->query($remind_query1))
{
$rows = $run1->num_rows;
for ($j = 0; $j < $rows; ++$j)//loop through each user in results and send a reminder email.
{
$run1->data_seek($j);
$row = $run1->fetch_array(MYSQLI_NUM);
$to = $row[3]; //gets the user email address
$subject = "Code 30 Reminder";
$message = "Hi ".$row[1]."\nJust a reminder that your membership date will expiry on the ".$row[6].",\n"
."Please renew your membership\n"."\nThank You"."\nINWASCON";
$headers = "From: INWASCON";
mail($to,$subject,$message,$headers);
}
echo "New record inserted sucessfully";
} else {
echo "Someone already register using this email";
}
}
$stmt->close();
$conn->close();
}
} else {
echo "All field are required";
die();
}
?>