I have a very simple code which checks whether email address exists in the table or not. If it exists then alert Already Exists and redirect to another page and if it doesn't exist then insert into table. Inserting when the email address is not present in the table is happening properly and is getting redirected to the respected page but when the email is existing in the table then although it alerts that username exists, it shows headers already sent at error
My code is
<?php
require_once('connection.php');
$tbl_name="cust_contacts";
$ccode=$_POST['ccode'];
$name=$_POST['name'];
$des=$_POST['desig'];
$dep=$_POST['dep'];
$phone=$_POST['phone'];
$mobile=$_POST['mob'];
$email=$_POST['email'];
$check="select * from $tbl_name where email='$email'";
$checkqry=mysql_query($check);
if($checkqry['error'])
die(mysql_error());
$countcheck=mysql_num_rows($checkqry);
if($countcheck==0)
{
$qry="insert into $tbl_name(cust_code,name,designation,department,phone,mobile,email) values('$ccode','$name','$des','$dep','$phone','$mobile','$email')";
if (!mysql_query($qry))
{
die('Error: ' . mysql_error());
}
header("location:index.php?customername=$ccode#pop4");
}
else
{
echo '<script type="text/javascript">alert("User already exists. Try editing the user");</script>';
header("location:index.php?customername=$ccode");
}
//$count=mysql_num_row($result);
//if($count==1)
?>