I have a launch page that accepts emails. I am trying to count the total number of emails in the table. However, I am struggling to get it to work. The sql seems to be accurate, because I ran the sql script in phpmyadmin and it returned the correct value. However, when I do a var_dump of the variable that I assigned the sql script it does not return the correct value. Any suggestions?
PHP
require(ROOT_PATH . "inc/database.php");
try {
$query = $db->prepare("REPLACE INTO launch_email VALUES ('$email')");
$query->execute();
$editEmail = $db->exec("SELECT COUNT(email) FROM launch_email");
var_dump($editEmail);
} catch (Exception $e) {
echo "Data could not be submitted to the database.";
exit;
}
}afterexit;--- Try and show the error message itself usingexit( $e->getMessage() );AS value_nameto assign a name and access, otherwise it will be returned as key-pairCOUNT(email). So:SELECT COUNT(email) AS ttl_emails FROM launch_email