4 Replies - 278 Views - Last Post: 25 April 2013 - 10:45 AM

#1 msz_900  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 40
  • Joined: 09-February 11

check user in database

Posted 25 April 2013 - 09:29 AM

HY to every one!
i want that when a user enter his name or any other data, then the data is checked in database and if it is already exists then it will show an error message, else it will save the data..
what type of function/method i used here...
if any one have any idea then please share it...

Thank's ...
Is This A Good Question/Topic? 0
  • +

Replies To: check user in database

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9497
  • View blog
  • Posts: 35,844
  • Joined: 12-June 08

Re: check user in database

Posted 25 April 2013 - 09:39 AM

Depends on the language.. but you'll need some sort of server side scripting language (like php) to send the data to a database, some sort of client side language to display the GUI/events (like html or javascript) to trigger the data to be sent to the database.. and at database to hold a stored procedure (and tables) that takes in the information you want to validate, checks against the table, and returns some sort of true/false or what ever indicating the data exists or not.
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3572
  • View blog
  • Posts: 10,414
  • Joined: 08-June 10

Re: check user in database

Posted 25 April 2013 - 10:21 AM

the least you will need is a UNIQUE (<= that’s SQL) index on the field(s) concerned. this way you cannot insert any duplicate data even if you bypass any other client or server-side language validation.
Was This Post Helpful? 0
  • +
  • -

#4 msz_900  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 40
  • Joined: 09-February 11

Re: check user in database

Posted 25 April 2013 - 10:29 AM

Thnk's to ever one my question has been solved..



$res = $dbh->query("SELECT *  FROM user_table WHERE user_name = '$userName'");
$l_records = $res->fetch();
if ($l_records) {
   // Code to display the error
}



this is the idea i needed..
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3572
  • View blog
  • Posts: 10,414
  • Joined: 08-June 10

Re: check user in database

Posted 25 April 2013 - 10:45 AM

in case of PDO, you could also do:
// init and config the PDO connection here ...
// using said DB constraint
try
{
    // shortened SQL statement for demo purpose
    $ps = $pdo->prepare("INSERT INTO user_table (user_name) VALUE (?)");
    // protection against SQL Injection
    $ps->bindValue(1, $_POST['username'], PDO::PARAM_STR);
    $ps->execute();
    echo "you have been successfully registered.";
}
catch (PDOException $e)
{
    echo "the username already exists.";
    error_log($e->getMessage());
}

This post has been edited by Dormilich: 25 April 2013 - 10:46 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1