| | |
accessing an empty querry result
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2008
Posts: 42
Reputation:
Solved Threads: 0
I wish to know if there is any way to refear to an empty querry result.
I want to implement a safety measure that prevents users from entering duplicate names in a DB. so I colect the value they enter in a textbox, then I create a querry wich checks the DB's name column for values that are identical to the user inputed value.
so basicly if no result is found it should continue to add the entry to the DB.
SO is there any way to check if a querry result is NULL and if so to execute a series of instructions?
I want to implement a safety measure that prevents users from entering duplicate names in a DB. so I colect the value they enter in a textbox, then I create a querry wich checks the DB's name column for values that are identical to the user inputed value.
so basicly if no result is found it should continue to add the entry to the DB.
PHP Syntax (Toggle Plain Text)
$sql_name_Check="SELECT DISTINCT table.name FROM table WHERE table.nume = '$name'"; $rez_name_Check = mysql_query($sql_name_Check) OR DIE (mysql_error()); IF ( ISNULL ($rez_name_Check) ) { code for adding the new entry }
SO is there any way to check if a querry result is NULL and if so to execute a series of instructions?
•
•
Join Date: Apr 2008
Posts: 296
Reputation:
Solved Threads: 11
You want to check user name exists or not i.e. avoid duplicate entry in database
PHP Syntax (Toggle Plain Text)
$sql_name_Check="SELECT table.name FROM table WHERE table.nume = '$name'"; $rez_name_Check = mysql_query($sql_name_Check) OR DIE (mysql_error()); $num=mysql_num_rows($rez_name_Check); if($num>1) { echo "User name already exists "; } else { echo "User name is available"; //Here insert value of form in database }
Last edited by Aamit; Dec 20th, 2008 at 9:37 am.
•
•
Join Date: Apr 2008
Posts: 296
Reputation:
Solved Threads: 11
PHP Syntax (Toggle Plain Text)
$sql_name_Check="SELECT table.name FROM table WHERE table.nume = '$name'"; $rez_name_Check = mysql_query($sql_name_Check) OR DIE (mysql_error()); $num=mysql_num_rows($rez_name_Check); if($num>=1) { echo "User name already exists "; } else { echo "User name is available"; //Here insert value of form in database }
Last edited by Aamit; Dec 22nd, 2008 at 1:32 am.
![]() |
Other Threads in the PHP Forum
- Previous Thread: mysql escape string
- Next Thread: PHP sort control
Views: 412 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cookies cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail mediawiki menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql stored structure subdomain syntax system table tutorial update updates upload url validation validator variable video web xml youtube





