<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

<?php
if(isset($_REQUEST['savetrack'])){
require_once('include/conn.php');
$num = $_POST['num'];
$receiveradd = $_POST['receiveradd'];
$status = $_POST['status'];
$destination = $_POST['destination'];
$exptdelvrydate = $_POST['exptdelvrydate'];

 

$actcode = "SELECT num FROM trackings WHERE  num = '$num' ";
$result = mysqli_query($login, $actcode) or die('MySql Error' . mysqli_error());
 if(!$actcode){
	echo "error" . mysqli_error();
}
if(mysqli_num_rows($result) > 0) {

	
	
	echo(" <div class='alert alert-danger alert-dismissable' align='center'>
                                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                             Oops Sorry: $num  Already in the System <a href='#' class='alert-link'></a>.
                            </div>");
}else{



 $sql = "INSERT INTO trackings (num,receiveradd,status,destination,exptdelvrydate) VALUES ('$num','$receiveradd','$status','$destination','$exptdelvrydate')";

 
 
 if ($login->query($sql) === TRUE) {
	 
	 echo(" <div class='alert alert-success alert-success' align='center'>
                                <button type='button' class='close' data-sucess='alert' aria-hidden='true'>&times;</button>
                           $num Record created successfully <a href='#' class='alert-link'></a>.
                            </div>");
} else {
    echo "Error: " . $sql . "<br>" . $login->error;
}

$login->close();
 
 
}
 
 
}
	  	
	  	
?>
<?php
//To Pull 7 Unique Random Values Out Of AlphaNumeric

$characters = array("0","1","2","3","4","5","6","7","8","9");

//make an "empty container" or array for our keys
$keys = array();

//first count of $keys is empty so "1", remaining count is 1-6 = total 7 times
while(count($keys) < 9) {
    //"0" because we use this to FIND ARRAY KEYS which has a 0 value
    //"-1" because were only concerned of number of keys which is 32 not 33
    //count($characters) = 33
    $x = mt_rand(0, count($characters)-1);
    if(!in_array($x, $keys)) {
       $keys[] = $x;
    }
}

foreach($keys as $key){
   @$random_chars .= $characters[$key];
}

//echo"VIP-$random_chars";

?>

<form id="form1" name="form1" method="post" action="">
  <table width="530" border="0" align="center" cellpadding="5" cellspacing="5">
    <tr>
      <td width="244">Tracking Number</td>
      <td width="251"><label for="num"></label>
      <input type="text" name="num" id="num" value="<?php echo "SLE".$random_chars?>" readonly="readonly" /></td>
    </tr>
    <tr>
      <td>Receiver's Address</td>
      <td><input type="text" name="receiveradd" id="receiveradd" /></td>
    </tr>
    <tr>
      <td>Destination</td>
      <td><input type="text" name="destination" id="destination" /></td>
    </tr>
    <tr>
      <td>Experted Delivery Date</td>
      <td><input type="text" name="exptdelvrydate" id="exptdelvrydate" /></td>
    </tr>
    <tr>
      <td>Status</td>
      <td><input type="text" name="status" id="status" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="savetrack" id="savetrack" value="Save Tracking" /></td>
    </tr>
  </table>
</form>
</body>
</html>