| | |
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: 293
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: 293
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
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax alerts apache api array beginner binary broken cakephp checkbox class cms code convert cron curl database date directory display download dynamic echo email error file files folder form forms function functions google hack href htaccess html htmlspecialchars image include insert integration ip java javascript joomla limit link login loop mail menu methods mlm mod_rewrite multiple mysql network object oop overwrite parse paypal pdf php problem query radio random recursion redirect regex remote script search securephp server sessions sms soap source space sql structure syntax system table tutorial update upload url validation validator variable video web xml youtube





