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];

Link to comment
Share on other sites

<?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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.