Link to home
Start Free TrialLog in
Avatar of Vishal Dhasmana
Vishal Dhasmana

asked on

Insert command not working but else are working

<?php
session_start();	
include "database.php";
$sql1 = "SELECT First_Name, Last_Name, Email , Password FROM register WHERE Email = '$_POST[email]'  "; 
$sql2 = "SELECT First_Name, Last_Name, Email , Password FROM register WHERE Phone = '$_POST[phone]'  "; 
$query1 = mysqli_query($conn,$sql1);
$row1 = mysqli_fetch_assoc($query1);
$query2 = mysqli_query($conn,$sql2);
$row2 = mysqli_fetch_assoc($query2);
if(!empty($row1) && !empty($row2))
{
	echo '1';
}
else 
	if(empty($row1) && !empty($row2))
	{
		echo '2';
	}
else 
	if(!empty($row1) && empty($row2))
		{
			echo '3';
		}
else
{
	$otp = mt_rand(100000,999999);
	$hash = md5(mt_rand(0,1000) );
	$pass = md5($_POST["password"]);
	$sql ="INSERT INTO register (First_Name, Last_Name, Email, Password, Phone,Otp,hash) VALUES ('$_POST[fname]','$_POST[lname]','$_POST[email]','$pass','$_POST[phone]','$otp','$hash')";
	$query = mysqli_query($conn,$sql);
	if($query) 
	{
		$_SESSION['login_user']=ucfirst($_POST["fname"])." ".ucfirst($_POST["lname"]);
		$_SESSION['email']=$_POST["email"];
		$to = $_POST["email"];
		$subject = "Email Verification";

		$message  = '<html><body>';
		$message .= '<h1 style="color:#128c7e;">Hello '. ucfirst($_POST["fname"]).' '.ucfirst($_POST["lname"]).'!</h1>';
		$message .= '<p style="color:#080;font-size:18px;">Thanks for signing up!
Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below.<br>
 
------------------------<br>
Username: '.$_POST["fname"].' '.$_POST["lname"].'<br>
Password: '.$_POST["password"].'<br>
MobileNo:  '.$_POST["phone"].'<br>
------------------------<br>
 
Please click this link to activate your account:<br>
http://reviewprix.com/verify.php?email='.$_POST["email"].'&hash='.$hash.'<br>
------------------------<br>
You can also enter OTP manually on our website for Verification.<br>
Your OTP is: '.$otp.'<br>
------------------------<br></p>';
		$message .= '</body></html>';
		$headers = "From: reviewcritic2k17@gmail.com \r\n";
		$headers .= "MIME-Version: 1.0\r\n";
		$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
		mail($to,$subject,$message,$headers);    
		echo '4';
	}	
}	
?>

Open in new window

Only insert query is not executing whereas everything is executing
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

I edited your question by placing your code in a code box.
http://support.experts-exchange.com/customer/portal/articles/349945

Scott
Topic Advisor
I can see how this logic gets a little fuzzy.

My first suggestion is to update your query to look for phone or email OR merge your two output array's http://php.net/manual/en/function.array-merge.php and just test if the merged array is empty or not.

The best would be to use just
$sql1 = "SELECT First_Name, Last_Name, Email , Password FROM register WHERE Email = '$_POST[email]' OR Phone = '$_POST[phone] "; 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial