Jump to content

How to check duplicate entry in registration form?


namasteji1

Recommended Posts

No, it isn't a bug. A string value used as an array index needs to be quoted. If left unquoted, php interprets it as a constant, just like it would do with any other unquoted string value. Don't believe me? Turn on error reporting (since it should be on while you're developing anyhow), and see for yourself.

 

error_reporting(-1);
ini_set('display_errors', 'On');

define('string', 'index');

$array = array( 'string' => 'Element with index "string"', 'index' => 'Element with index "index"' );
echo $array[string];
echo '<br>';
echo $array['string'];
echo '<br>';
echo $array['index'];
echo '<br>';
echo $array[index];

<?php
session_start();session_destroy();
session_start();



if($_POST["regname"] && $_POST["regemail"]
&& $_POST["regmobile"] && $_POST["regpass1"] && $_POST["regpass2"] )

{
if($_POST["regpass1"]==$_POST["regpass2"])
{
$servername="localhost";
    $username="root";
    $conn=  mysql_connect($servername,$username)or die(mysql_error());
    mysql_select_db("test",$conn);
    

$sql = "SELECT `id` from users where `email`= ".$_POST['regemail']."' LIMIT 1";
   $result=mysql_query($sql,$conn) or die(mysql_error());		
$mail_rows = mysql_num_rows($result);
$sql = "SELECT `id` from users where `regname`= '".$_POST['regname']."' LIMIT 1";
   $result=mysql_query($sql,$conn) or die(mysql_error());		
$name_rows = mysql_num_rows($result);
if($mail_rows==0&&$name_rows==0) 
{
$sql="insert into users (name,email,mobile,password)values('$_POST[regname]','$_POST[regemail]','$_POST[regmobile]','$_POST[regpass1]')";
    $result=mysql_query($sql,$conn) or die(mysql_error());		

    print "<h1>you have registered sucessfully</h1>";
   
    print "<a href='index.php'>go to login page</a>";
}
else echo "duplicated data";
}

else print "Passwords doesn't match";
}
else print"Invalid input data";

?>

 

I am getting a sql error, error in where clause for regname and also i would like to know where to put separate echo statements for duplicate username as well as username please?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.