Ask Question

Menu


Birthday Wish Send Automatically project in PHP


This project is all about how to send birthday wish automatically.

birth_day table
CREATE TABLE `birth_day` (
`user_id` int(11) NOT NULL,
`name` varchar(30) NOT NULL,
`birth_day` varchar(20) NOT NULL,
`birth_day_a` varchar(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

database.php

<?php
error_reporting(1);
$servername = "localhost";
$username = "root";
$password = "";
$dbname= "student";
// Create connection
$conn = new mysqli($servername, $username, $password ,$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>

insert.php

<?php
include_once 'database.php':
if(isset($_POST['save']))
{
try {
$name = $_POST['name'];
$birth_day = $_POST['birth_day'];
$birth_day_a=substr("$birth_day",5);//send the month and day to database
//database connection
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
//database connection
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO birth_day (name,birth_day,birth_day_a)
VALUES ('$name','$birth_day','$birth_day_a')";
$conn->exec($sql);
$message = "New member data added successfully. Name : ".$name." ";
}
catch(PDOException $e)
{
echo $sql . "
" . $e->getMessage();
}
$conn = null;
}
?>
<!DOCTYPE HTML>
<html>
<body>
<div><?php if(isset($message)) { echo $message; } ?>
</div>
<form method="post" action="">
Name:<br>
<input type="text" name="name" placeholder="Name">
<br>
Birthday:<br>
<input type="text" name="birth_day" placeholder="Birthday (yy-mm-dd)">
<br><br>
<input type="submit" value="Submit" name="save">
</form>
</body>
</html>

index.php

<?php
include_once 'database.php';
date_default_timezone_set("Asia/Calcutta");
$date = date("Y-m-d"); //Today date
$birth=substr("$date",5);
$result = mysqli_query($conn,"SELECT * FROM birth_day where birth_day_a='".$birth."';");//Select the birthday list
?>
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
</head>
<table class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th><input type="checkbox" id="checkAll"> Select All</th>
<th>User Id.</th>
<th>Name</th>
<th>Birthday date</th>
</tr>
</thead>
<tfoot>
<tr>
<th>#</th>
<th>User Id.</th>
<th>Name</th>
<th>Birthday date</th>
</tr>
</tfoot>
<tbody>
<form method="post" action="send-wish.php">
<?php
$i=0;
while($row = mysqli_fetch_array($result)) {
?>
<tr>
<td>
<input type="checkbox" id="checkItem" name="check[]" value="<?php echo $row["email"]; ?>">
</td>
<td><?php echo $row["user_id"]; ?></td>
<td><?php echo $row["name"]; ?></td>
<td><?php echo $row["birth_day"]; ?></td>
</tr>
<?php
$i++;
}
?>
</tbody>
</table>
<p align="center"><button type="submit" class="btn btn-success" name="save">Send Birthday Wishes </button></P>
</form>
<script>
$("#checkAll").click(function () {
$('input:checkbox').not(this).prop('checked', this.checked);
});
</script>
</body>
</html>

send-wish.php

<?php
if(isset($_POST['save'])){
$wish= $_POST['wish'];
$checkbox1 = $_POST['check'];
$chk="";
foreach($checkbox1 as $chk1)
{
$chk.= $chk1.", ";
}
$checkbox2 = $_POST['email'];
$chk1="";
foreach($checkbox2 as $chk2)
{
$chk1.= $chk2.", ";
}
$to = $chk;
$subject = "Happy birthday";
$txt = "Happy birthday! Dear";
$headers = "From: name@example.com" . "\r\n" .//your mail id
"CC: somebodyelse@example.com";//if any (optional)
mail($to,$subject,$txt,$headers);
echo 'Birthday Wish Send Successfully.'; }
?>



Buy Template