PHP 中的 Toastr 代码示例

在这篇文章中,我们将学习如何在 PHP 代码示例中制作 Toastr。我简单地一步步解释了如何使用 toaster php 代码示例。在这里您将学习如何在 Php 中使用 Toastr?。本教程将为您提供如何在表单提交后显示 Toastr 的简单示例。

我将为您提供如何在 PHP 代码示例中制作 Toastr 的简单示例。

让我们看下面的例子:

index.php

<!DOCTYPE html>
<html>
<head>
<title>Toastr in PHP Code Example</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
<style>
.toast
{
position: absolute;
top: 10px;
right: 10px;
}
</style>
</head>
<body class="bg-dark">
<div class="container mt-5 pt-5" >
<div class="card mt-3">
<div class="card-header text-center bg-info text-white">
<h1>Toastr in PHP Code Example</h1>
</div>
<div class="card-body">
<form id="submit_form">
<div class="mb-3">
<label>Email : </label>
<input type="email" name="email" id="email" class="form-control" />
</div>
<div class="mb-3">
<label>Message : </label>
<textarea name="message" id="message" class="form-control" rows="5" ></textarea>
</div>
<div class="d-flex justify-content-center">
<input type="button" name="submit" id="submit" class="btn btn-primary" value="Submit" />
</div>
</form>
</div>
</div>
<div class="toast" id="myToast" data-bs-autohide="true">
<div class="toast-header">
<strong class="me-auto"><i class="bi-bell-fill"></i>notification</strong>
<small>1 sec ago</small>
<button type="button" class="btn-close" data-bs-dismiss="toast"></button>
</div>
<div class="toast-body">
<p id="error_message"></p>
<p id="error_message"></p>
</div>
</div>
</div>
</div>
</div>
</div>
<script>

$(document).ready(function(){
(document).ready(function(){
$('#submit').click(function(){
('#submit').click(function(){
var email = $('#email').val();
var email = $('#email').val();
var message = $('#message').val();
var message = $('#message').val();
if(email == '' || message == ''){
if(email == '' || message == ''){
$('#error_message').html("All Fields are required");
('#error_message').html("All Fields are required");
$('.toast').toast('show');
('.toast').toast('show');
}else{
}else{
$.ajax({
.ajax({
url:"insert.php",
:"insert.php",
method:"POST",
:"POST",
data:{email:email, message:message},
:{email:email, message:message},
success:function(data){
:function(data){
$('.toast').toast('show');
('.toast').toast('show');
$('#error_message').html(data);
('#error_message').html(data);
}
}
});
});
}
}
});
});
});
});
</script>

</body>

</html>

 

insert.php

<?php
php
$servername = "localhost";
= "localhost";
$username = "root";
= "root";
$password = "root";
= "root";
$dbname = "aatman";
= "aatman";

$conn = new mysqli($servername,$username,$password,$dbname);
= new mysqli($servername,$username,$password,$dbname);

if($conn->connect_error){
if($conn->connect_error){
die ('connection faild:'.$conn->connect_error);
die ('connection faild:'.$conn->connect_error);
}
}

$email = $_POST['email'];
= $_POST['email'];
$message = $_POST['message'];
= $_POST['message'];
$sql = "INSERT INTO users (email,message)VALUES('$email','$message')";
= "INSERT INTO users (email,message)VALUES('$email','$message')";

if ($conn->query($sql)===TRUE) {
if ($conn->query($sql)===TRUE) {
echo "message sent successfully";
"message sent successfully";
}else{
}else{
echo "Error: ".$sql."<br>".$conn->error;
"Error: ".$sql."<br>".$conn->error;
}
}

$conn->close();
->close();
?>

输出:

THE END
分享
二维码
海报
PHP 中的 Toastr 代码示例
在这篇文章中,我们将学习如何在 PHP 代码示例中制作 Toastr。我简单地一步步解释了如何使用 toaster php 代码示例。在这里您将学习如何在 Php 中使用 Toastr……
<<上一篇
下一篇>>