| | |
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 |
action ajax apache api array basic beginner binary broken cakephp checkbox class cms code computing confirm cron curl database date delete display domain dynamic echo email error fatalerror file files folder form forms function functions google header href htaccess html iframe image include indentedsubcategory insert interactive ip javascript joomla limit link load login mail malfunction menu mlm msqli_multi_query multiple mysql navigation neutrality oop paging parse paypal pdf php procedure query radio ram random record reference remote return script search server sessions source space sql syntax system table tutorial unset update upload url validation validator variable video web websitecontactform xml youtube





