| | |
mysql_numrows not working??
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Hey
Im having this problem, im sure theres a simple solution, but i cant seem to see it
The code bellow is part of a regestration form validation. Basicly when i ask the database if anyone else exists with the same username, password or email address - it works
BUT
Only if it returns 1 or more rows!
If no-one else exists with the username ect. it returns my error message (couldnt check rows).
All help would be greatly appreciated!
Thanks
Im having this problem, im sure theres a simple solution, but i cant seem to see it

The code bellow is part of a regestration form validation. Basicly when i ask the database if anyone else exists with the same username, password or email address - it works
BUT
Only if it returns 1 or more rows!
If no-one else exists with the username ect. it returns my error message (couldnt check rows).
PHP Syntax (Toggle Plain Text)
<form method="post" name="details"> <b class="form_title">First Name: </b><input type="text" name="first_name" class="form_box" /> <br /> <b class="form_title">Last Name: </b><input type="text" name="last_name" class="form_box"/> <br /> <b class="form_title">Age: </b><input type="text" name="age" class="form_box" /> <br /> <b class="form_title" >Email: </b><input type="text" name="email" class="form_box" /> <br /> <b class="form_title" >Phone: </b><input type="text" name="phone" class="form_box" /> <br /> <b class="form_title">Address: </b><textarea name="address" class="form_box"></textarea> <br /> <b class="form_title" >Username: </b><input type="text" name="username" class="form_box"/> <br /> <b class="form_title" >Password: </b><input type="password" name="password1" class="password"/> <br /> <b class="form_title" >Repeat: </b><input type="password" name="password2" class="password" /> <br /> <b class="form_title">I accept the terms of using this website </b> <input type="checkbox" name="terms" class="form_box" /> <br /> <input type="submit" value="Regester Me"/> </form> <?php $priv = "LIMITED"; $first_name = $_REQUEST["first_name"]; $last_name = $_REQUEST["last_name"]; $age = $_REQUEST["age"]; $email = $_REQUEST["email"]; $phone = $_REQUEST["phone"]; $address = $_REQUEST["address"]; $username = $_REQUEST["username"]; $pass1 = $_REQUEST["password1"]; $pass2 = $_REQUEST["password2"]; $terms = $_REQUEST["terms"]; if (empty($first_name) || empty($last_name) || empty($age) || empty($email) || empty($phone) || empty($address) || empty($username) || empty($pass1) || empty($pass2)) { $error = "You Must Fill In All The Boxs."; } elseif ($pass1 != $pass2) { $error = "Your Passwords Must Match."; } elseif ($terms != "on") { $error = "You Must Accept The Terms"; } else { $check_email = "SELECT email,username,password FROM members WHERE email = '$email' OR username = '$username' OR password = '$pass1'"; $check_email_sql = MYSQL_QUERY($check_email) or die ("Could send email check"); $email_rows = MYSQL_NUMROWS($check_email_sql) or die ("couldnt check rows"); } echo $email_rows; ?> <br /> <u class="error"><?php echo $error ; ?></u> <div id="space"> </div> </div>
All help would be greatly appreciated!
Thanks
Last edited by peter_budo; Apr 27th, 2008 at 5:05 am. Reason: Keep It Organized - please use [code] tags
It may be producing an error because there are no rows.
You might be better to write the script as:
You might be better to write the script as:
php Syntax (Toggle Plain Text)
$email_rows = mysql_num_rows($check_email_sql); if($email_rows>0){ echo $email_rows; }else if($email_rows==0){ echo 'No Rows Found'; }
If my post is useful please add to my reputation.
Thanks.
Ajtrichards Web Solutions | http://www.ajtrichards.co.uk
Retenovate | http://www.retenovate.com
Thanks.
Ajtrichards Web Solutions | http://www.ajtrichards.co.uk
Retenovate | http://www.retenovate.com
I think it's because when the row return's zero then php thinks it's an error so it runs the die() function.
I always write my scripts like the one I showed you and I never have a problem.
Please use "Add to Phper's reputation" if you found my post usefull!
Thanks
I always write my scripts like the one I showed you and I never have a problem.
Please use "Add to Phper's reputation" if you found my post usefull!
Thanks
If my post is useful please add to my reputation.
Thanks.
Ajtrichards Web Solutions | http://www.ajtrichards.co.uk
Retenovate | http://www.retenovate.com
Thanks.
Ajtrichards Web Solutions | http://www.ajtrichards.co.uk
Retenovate | http://www.retenovate.com
why would you want to check for password? not needed!
btw $email_rows = MYSQL_NUMROWS($check_email_sql); should be $email_rows = MYSQL_NUMROWS($check_email)
you need to use mysql_real_escape_string($username) on db also
username='".mysql_real_escape_string($username)."'
btw $email_rows = MYSQL_NUMROWS($check_email_sql); should be $email_rows = MYSQL_NUMROWS($check_email)
php Syntax (Toggle Plain Text)
$email_rows =mysql_affected_rows(); if($email_rows>0){ echo $email_rows; }else if($email_rows==0){ echo 'No Rows Found'; }
you need to use mysql_real_escape_string($username) on db also
username='".mysql_real_escape_string($username)."'
Last edited by peter_budo; Apr 29th, 2008 at 9:46 am. Reason: Keep It Organized - please use [code] tags
I believe it's mysql_num_rows(), in addition, in case you wanna switch to mysqli result object, it's $result -> num_rows;
ah yes yang, few typos there.
$email_rows = MYSQL_NUMROWS($check_email_sql); should be $email_rows = MYSQL_NUM_ROWS($check_email_sql)
$email_rows = MYSQL_NUMROWS($check_email_sql); should be $email_rows = MYSQL_NUM_ROWS($check_email_sql)
![]() |
Similar Threads
Other Threads in the PHP Forum
- Previous Thread: Parse error help...
- Next Thread: Help with image resizing!!!
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail mediawiki menu mlm mod_rewrite multiple mysql number oop parse paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search server sessions sms soap source space speed sql structure subdomain syntax system table tag tutorial update upload url validation validator variable vbulletin video web websphere white xml youtube





