i created a student attendance system in php core, where lecturer can generate random number that student should use unique code for students attendance after class
the system is working but it’s repeating the this alert “Token Generate successfully” by the numbers of (for loop condition) so there’s any way to implement it without repeat the alert?
i need to generate multi unique code but with only one alert per submit instead of multi alert and here’s my code
php file
<?php
session_start();
//require 'data.php';
require "con_dr.php";
//$crypt = new encryption_class;
$nom = mysqli_real_escape_string($con, $_POST['nom']);
for($i==0;$i<$nom;$i++)
{
$pinno='';
$characters = array("1","2","3","4","5","6","7","8","9");
$keys = array();
while(count($keys) < 3) {
$x = mt_rand(0, count($characters)-1);
if(!in_array($x, $keys)) {
$keys[] = $x;
}
}
foreach($keys as $key){
$pinno .= $characters[$key];
}
$pinno=$pinno.rand(100,999);
$level = mysqli_real_escape_string($con, $_POST['level']);
$course = mysqli_real_escape_string($con, $_POST['code']);
$coursename = mysqli_real_escape_string($con, $_POST['coursename']);
$sdate = mysqli_real_escape_string($con, $_POST['sdate']);
$edate = mysqli_real_escape_string($con, $_POST['edate']);
$lectid ='Softera';
$status = 0;
$stquer = $con->query("INSERT INTO pin (token,coursecode,coursename,level,status,sdate,edate,lectid) VALUES
('$pinno','$course', '$coursename','$level', '$status', '$sdate','$edate','$lectid')");
if ($stquer) {
echo "<span class='alert alert-success'> Token Generate successfully </sapn>";
} else {
echo "<span class='alert alert-danger'> Error While Saving</sapn>";
}
}
?>
$(document).on("click", "#toker", function() {
alert("hello nura");
var level = $("#level").val(),
code = $("#code").val(),
coursename = $("#coursename").val(),
nom = $("#nom").val(),
sdate = $("#sdate").val(),
edate = $("#edate").val();
$.ajax({
method: "POST",
data: {
level :level,
code :code,
coursename:coursename,
sdate:sdate,
nom: nom,
edate:edate
},
url: "/attendance/code.php",
success: function(response) {
$("#settingsalert").slideDown(function() {
$(this).html(response);
});
setTimeout(function() {
$("#settingsalert").slideUp();
}, 4000);
}
});
});