1
Answer

check if a user email is exist in database if user

<?php
session_start();
$conn = mysqli_connect("localhost", "ODBC", "", "spynews_db");
if(mysqli_connect_errno()){
echo "Unable to connect" .mysqli_connect_error();
exit();
}else{
if(isset($_POST["submit"])){
//echo $_POST["submit"];
$password = "";
$charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for($i = 0; $i < 8; $i++){
$random_int = mt_rand();
$password .= $charset[$random_int % strlen($charset)];
}
//echo $password, "\n";
$sql = 'INSERT INTO users VALUES (?,?,?,?,?,?)';
$stmt = mysqli_stmt_init($conn);
if(mysqli_stmt_prepare($stmt,$sql)){
mysqli_stmt_bind_param($stmt,'ssssss',$user_email,$user_name,$user_surname,$user_date_of_birth,$user_gender,$password);
$user_name =$_POST["name"];
$user_surname =$_POST["surname"];
$user_gender =$_POST["gender"];
$user_date_of_birth =$_POST["dateofbirth"];
$user_email =$_POST["email"];
$to = $_POST["email"];
$from = "From:[email protected]";
if(!isset($_POST["email"]) || $_POST["email"] == null){
echo "Please enter a valid email address";
}else{
$result = mail($to, $_POST['name'],
$password,$from);
if(!$result){
echo "Error sending message";
}else{
echo "message sent";
}
}
mysqli_stmt_execute($stmt);
$stmt->close();
echo"User Registered";
$conn->close();
}else{
echo "Failed to Register";
}
}
}
?>
<html>
<head>
<title>Registration</title>
</head>
<div class="form">
<body bgcolor="#EAEAEA">
<img src="deliver.png" alt="flower" width="300" height="95" />
<center>
<fieldset style="width:50%"><legend><h3>Registration Form</h3></legend>
<table>
<form name="registration" action="RegisterForm.php" method="post">
<tr>
<td>Name:</td>
<td><input type="text" name="name" placeholder="Name" required /></td>
</tr>
<tr>
<td>Surname:</td>
<td><input type="text" name="surname" placeholder="Surname" required /></td>
</tr>
<tr>
<td>Gender:</td>
<td><input type="radio" name="gender" value="Male"/>Male
<input type="radio" name="gender" value="Female"/>Female
</tr>
<tr>
<td>D.O.B:</td>
<td><input type="date" name="dateofbirth" placeholder="Date Of Birth" required /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="email" name="email" placeholder="Email" required /></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit" /></td><br/>
</tr>
<tr>
<td><a href='Index.php'>Home</a></td>
<td><a href='Login.php'>Login</a></td>
</tr>
</form>
</div>
</body>
</html>
Answers (1)