0

i wrote the following query

SELECT COUNT(userID) From statistics WHERE userID = ""

this query displays the number of unathunticated visit to the website.

the query works in phpmyadmin when i use double quotes however it doesnt when i use single quotes like below it just gives me the number of record stored in the table

 $queryB = "SELECT COUNT(userID) From statistics WHERE userID = ''";
 $resultB =mysql_query($queryA, $con) or die(mysql_error());
 $authB = mysql_result($resultB, "COUNT(userID)");

 echo "the number of authenticated visits were $authB<br />\n";

i've no idea why it breaks, any ideas?

5 Answers 5

4

you store your query in $queryB but you use $queryA

Sign up to request clarification or add additional context in comments.

1 Comment

+1 nice catch.I would bet that $queryA was a test with no WHERE clause.
0

not sure if it will work...its just first think that came to mind: how about when u use escaped double quotes?

$queryB = "SELECT COUNT(userID) From statistics WHERE userID = \"\""

Comments

0

Try this:

 $queryB = "SELECT COUNT(userID) AS total From statistics WHERE userID = ''";
 $resultB =mysql_query($queryB, $con) or die(mysql_error());
$authB = mysql_fetch_assoc($resultB);
 echo "the number of authenticated visits were ".$authB['total']."<br />\n";

Comments

0

Does userID have a default value? If the default value is NULL, then change your query to

$queryB = "SELECT COUNT(userID) From statistics WHERE userID IS NULL"; 

Comments

0

you should change a little to your code

$queryB = "SELECT COUNT(userID) From statistics WHERE userID = ''";
$resultB =mysql_query($queryB, $con) or die(mysql_error());
$authB = mysql_result($resultB, 0, 0);

echo "the number of authenticated visits were $authB<br />\n";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.