Try to count the emails but it doesn't work(and don't show any message)

            $email = $user->email;

            $sql = $pdo->prepare ("SELECT COUNT(email) FROM users WHERE email = :email");

            $sql->bindParam(':email', $email);
            
            $sql->execute();
            
            while ($row = $sql->fetch()) {
                echo $row['COUNT(email)'];
            }

There are a couple of things you can do to make sure you’re seeing all errors.

Add the following code to the top of your file; this will show all PHP errors.

ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

When you create your $pdo object, add the followinig as the fourth argument: [ \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION ]. If you’re already passing a fourth argument, just add the key and value to it. This will print out any db interaction errors as an exception.

If you do both of those, what errors do you see?

First thing, thanks for help me!
i tried both but it still not working and don’t show nothing.
I tried this code(it works on other project of mine) but it doesn’t work… XD

$email = $user->email;

            $sql ="SELECT COUNT(email) FROM users WHERE email = $email";

            $res = $pdo->query($sql);
            
            while( $row = $res->fetch()) {

                echo $row['COUNT(email)'];
            }

What happens if instead of:

echo $row['COUNT(email)'];

you have

var_dump($row);

just tried but nothing :confused:

$res = $pdo->query($sql);
var_dump($res); // <--- add this line            
while( $row = $res->fetch()) {

What about now?

Nothing, i really don’t understand, because with the same code and db of other project of mine it works but with this one nothing :frowning:

Something I missed or I coded wrong I think

If ‘nothing’ means you are getting a blank page, you probably have a php syntax error. You need to make the suggested error related settings in the php.ini on your system, so that ALL php errors will get reported and displayed. While you are making changes to the php.ini set output_buffering to OFF. You should then restart your web server to insure any changes made the the php.ini take effect and use a phpinfo(); statement in a php script file to insure that the settings actually got changed to the new values.

output_buffering is setted OFF
Nothing means that nothing happens…
Until this code all is ok, the problem is when program run this code(nothing happens).

Do you get any output when you add an echo 'something here'; statement to your code?

If not, you are going to need to post all the code for the page, less any database connection credentials.

I write again the PDO connection code and now it works…but I still don’t understand what happened… :confused:
Anyway I want to thanks all of you for help me :slight_smile:

A problem with the connection code, either a php syntax error or a connection that failed, combined with putting the suggested settings in the php.ini, should have produced php errors pointing to the problem.

You didn’t actually confirm if you were getting a blank page. It’s also possible that where the php code is at in the html markup for the page, that any php runtime errors might not get displayed. They would appear in the ‘view source’ of the page in your browser. If this is what is occurring, organizing the code on the page so that most of the php code is before the start of the html document will help.

Sponsor our Newsletter | Privacy Policy | Terms of Service