Hey, im having a problem getting this email check to work it basicly prints out in a very origional way how manny eails you have...
Check Inbox (3)

Heres the code:

$find_content = "SELECT * FROM email WHERE email_too_id = '$userid' OR all = 'true'";
$content_sql = mysql_query($find_content) or die ("Couldnt send sql for email content".mysql_error());
$email_ammount = mysql_num_rows($content_sql);
if ($email_ammount == 0) {
$num = 0;
else {
$num = $email_ammount;

However i am getting the following error message :

Couldnt send sql for email contentYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'all = ''' at line 1

The check for all just checks weither someones sent an email in which all people will receive on my website.

Please help, its really annoying me :D


10 Years
Discussion Span
Last Post by Designer_101

all is a reserve word. It is not a good practive to use reserve words in query. If it is required to use such words, then simply use back ticks (`) around them as I did in the below query.

$find_content = "SELECT COUNT(*) AS total_mails FROM email WHERE email_too_id = '$userid' OR `all` = 'true'";
$content_sql = mysql_query($find_content) or die ("Couldnt send sql for email content".mysql_error());
$email_ammount = mysql_fetch_array($content_sql);
$num = intval($email_ammount["total_mails"]);

I have rewritten the code for you to work efficiently. There is no need to use mysql_num_rows(). This takes much more time and resources when you run it on a large result set.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.