Jump to content

[SOLVED] How to prevent multiple entries to db...


mmarif4u

Recommended Posts

Hi everybody,,,
I am facing problem,
Problem is that i have a user with ic already have in my database.
But my query enter another data to db when i try to enter that ic
again.i want that only one ic exist in db.i make query but t only checks the
format like 1234 or 5462313 not 123aa and 123333-12-1234
I want to check the format like 123456-12-1234..
My query is:
[code]
// Check for existing user with the ic number
    $sql = "SELECT COUNT(*) FROM loguser WHERE icnumber = $ic ";
    $result = mysql_query($sql);
    if (!$result) {
        error('A database error occurred in processing your '.
            'submission.\\nIf this error persists, please '.
              'contact [email protected].');
    }
   
   
    if (mysql_result($result,0,0)>0)  {
        error('A user already exists with your chosen IC Number.\\n'.
              'Please try your own IC Number.');
    }
    if (preg_match('#^[0-9]{6}-[0-9]{2}-[0-9]{4}$#', $ic))
    {}else{     
    error('IC Number format is not Valid.\\n'.
              'Please try again.');
      }
[/code]

plz any one has idea about it,,
i think the error is here thats why it didnot check the format entered.
[code]
if (mysql_result($result,0,0)>0)  {
[/code]

Thanks in advance..
Actully i have two tables..

This is access table:
[code]
CREATE TABLE `access` (
  `icnumber` varchar(45) default NULL,
  `acccode` varchar(45) default NULL,
  `actdate` varchar(45) default NULL,
  `expdate` varchar(45) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
[/code]

this is loguser table:
[code]
CREATE TABLE `loguser` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `icnumber` varchar(45) default NULL,
  `username` varchar(45) default NULL,
  `fullname` varchar(45) default NULL,
  `hp` varchar(45) default NULL,
  `email` varchar(45) default NULL,
  `password` varchar(45) default NULL,
  `creationdate` varchar(45) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
[/code]
Not sure if this is what you mean, but here is how I prevent others users from making the same unsername:

[code]

$tilkobling = CONNECT("USER");
$sql = "SELECT * FROM USER WHERE USERNAME='$_USERNAME'";
$resultat = mysql_query($sql, $tilkobling);

$rad = mysql_fetch_array( $resultat );

if($rad['USERNAME'] == ' ')
{

mysql_query ("INSERT INTO USER (USERNAME) VALUES ('$_USERNAME'')");
echo "<br><br><b>SUCKSESS!</b><br>";

}
else
{
echo "<br><b>USERNAME TAKEN!!</b><br>";
}
}
[/code]

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.