Forum Moderators: coopster

Message Too Old, No Replies

getting the error every time....

something with the COUNT(*), maybe?

         

mylungsarempty

6:39 am on Oct 23, 2003 (gmt 0)

10+ Year Member



This is supposed to check and see if the user name exists... but when i include the if statement, i get the error every time, and only reason i can figure might be something to do with COUNT(*) ... maybe that's screwed up... i dont know... someone know why i get the error every time here?

$sql = "SELECT COUNT(*) FROM musicians WHERE username = '$newname'";
$result = mysql_query($sql);
if (!$result) {
error('A database error occurred in processing your '.
'submission.\\nIf this error persists, please '.
'contact somone@asite.net.');
}

[edited by: jatar_k at 3:24 pm (utc) on Oct. 23, 2003]
[edit reason] generalized [/edit]

RonPK

9:54 am on Oct 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



* Exactly what error do you get?
* there is no function called 'error()'.
* if you suspect an error in your query, try
$result = mysql_query($sql) or die(mysql_error());

to produce the mysql error.

charlier

10:16 am on Oct 23, 2003 (gmt 0)

10+ Year Member



I think you need to have a group by clause to use the count function. Check the doco. at www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#GROUP-BY-Functions. If you just want to get the number of records then you can use mysql_num_rows to get that. One suggestion for general developement of php/mysql is to install a web client for mysql like phpmyadmin then you can run all your queries by hand for testing.

Cheers
Charlie

coopster

10:52 am on Oct 23, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Syntax is fine, no GROUP BY clause needed with COUNT(*).

Try RonPK's suggestion to get your error.