Getting row count in myslqli with php

Shelldon

Active Member
Joined
May 30, 2012
Messages
53
Reaction score
0
Hi all. I'm trying to learn php, but am really struggling with a registration page.

I have this...

Code:
32. $check_email = $connect->query("SELECT email FROM tbl_users WHERE email='$email'");
33. $count = $check_email->num_rows;

I keep getting an error of "Notice: Trying to get property of non-object in C:\xampp\...\register.php on line 33"

I just can't seem get this right. I did look at the php man page but I can't see a difference in the way that they do it and I do it. What am I missing?

Thanks
 
Why not just:

select count(email) FROM tbl_users WHERE email='$email'

?
 
Hi all. I'm trying to learn php, but am really struggling with a registration page.

I have this...

Code:
32. $check_email = $connect->query("SELECT email FROM tbl_users WHERE email='$email'");
33. $count = $check_email->num_rows;

I keep getting an error of "Notice: Trying to get property of non-object in C:\xampp\...\register.php on line 33"

I just can't seem get this right. I did look at the php man page but I can't see a difference in the way that they do it and I do it. What am I missing?

Thanks

I have a feeling this is your problem:
33. $count = $check_email->num_rows;

$check_email is not an object, and you are trying to access one of its properties.

That is the reason for your error

It is probably not being sent to your view, or $check_email is empty.
 
See PHP manual here: http://php.net/manual/en/pdostatement.rowcount.php
Code:
<?php
/* Delete all rows from the FRUIT table */
$del = $dbh->prepare('DELETE FROM fruit');
$del->execute();

/* Return number of rows that were deleted */
print("Return number of rows that were deleted:\n");
$count = $del->rowCount();
print("Deleted $count rows.\n");
?>
 
Thanks all

After reading your comments I sat down and puzzled it for a while, I realised that although I was connecting to the server, I hadn't specified the database to connect to. So corrected that in my connect.php script and all works beautifully!

I would like to know one other thing though. I've got an index page with a link to signup, and right now I'm sending users onto a registration page. I was wondering if it's not better to have a pop-up with the registration option on there so as to avoid having users being sent from page to page?

Could I achieve that using javascript?
 
Yea, You can use a model to come in after a while where the user can sign up/register/login

Code:
setTimeout(function(){
$('#memberModal').modal('show');

},2000);
 
Yea, You can use a model to come in after a while where the user can sign up/register/login

Code:
setTimeout(function(){
$('#memberModal').modal('show');

},2000);

Thanks for this!
 
Top
Sign up to the MyBroadband newsletter
X