<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {

	require "../includes/db1.php";

	$password = trim(password_hash($_POST['password'], PASSWORD_DEFAULT));
	$username = trim($_POST['username']);


	$sql = "INSERT INTO accounts1 (username, password1, email, level1)
			VALUES ('" . mysqli_escape_string($con, $username) . "', '"
						. mysqli_escape_string($con, $password) . "', '"
						. mysqli_escape_string($con, $_POST['email']) . "', '"
						. mysqli_escape_string($con, $_POST['level1']) . "')";

	$results= mysqli_query($con, $sql);

	if ($results === false) {
	  echo mysqli_error($con);
	} else {
	  $id = mysqli_insert_id($con);
echo "Login info for: " .$username ; echo "<br>";
echo "Data Submitted successfully the ID is:  $id ";  echo "<br>";
echo " The username is: ".$username ; echo "<br>";
echo " The password is: " .$_POST['password'] ;  echo "<br>";
echo " Authorization access:  "  .$_POST['level1'];  echo "<br>";

$p = $_POST['password'];

 $test = " Hello $username  This is your login info /n your  username: $username  your Password: $p ";

//Email login info to user. But one should be automatic. the other should be on button click
$email = $_POST['email'];
    $TextBody = "From New Jerusalem Haitian Baptist Church";
    $Subject = "Login Info";
    $headers = 'from: pastorclaudetsaintil@newjerusalemonline.org';
   mail($email, $Subject, $test, $headers);
	}

  }
   ?>
   <div>
   <form action="emailprocessing.php" method="POST">
  <input type="email" name="email"  value="<?= $email ?>" id="" placeholder="enter email">
  <input type="hidden" name="headers"  value="<?= $headers ?>" id="">
 <textarea name="emailmessage" id="" cols="30" rows="10" value="<?= $test ?>" hidden ></textarea>
<button>Email login Info</button>
</form></div>
