<?php 
session_start();
$iduser=$_SESSION['user_idd'];
$date = new DateTime("now", new DateTimeZone('Africa/Nairobi') );
$timenow=$date->format('Y-m-d H:i:s');
$timenow2=$date->format('Y-m-d');
$month=$date->format('M');

function createRandomPassword() {
$chars = "003232303232023232023456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 7) 
{
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}

$code=createRandomPassword(8);

include('../include/config.php');

 if(isset($_POST["grd"]))
 { 
 $grd=addslashes($_POST["grd"]);
 $msg=addslashes($_POST["msg"]);
 
 $sql=mysqli_query($con,"UPDATE pupils SET Msg='$msg',SS='$code' WHERE Claz='$grd'");
 
 $sqll=mysqli_query($con,"INSERT INTO SS( `Contact`, `Ses`, `Msg`, `Grade`) select Contact,SS,Msg,Claz from pupils where Claz='$grd'");
if($sql)
{
 echo $code;
}else
{
echo "Error in sending some emails";
}
 }
?>