Hi All, I am new to PHP, I have tried to look for similar error but could not find anwers that helped me. I am getting the following error: Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in C:\ ... register.php on line 109 Here is my code snippets: 1.) my connection to the database is per page. the first three lines of code in my script is : <?php session_start(); mysql_connect("localhost", "USER", "PASS") or die(mysql_error()); mysql_select_db("DATABASE") or die(mysql_error()); which means that I do not use persistant connections 2.) the code that creates the error is this: $checkSQL = "SELECT COUNT(`EmailAddress`) AS `CountOfRows` FROM `printerclient` WHERE `EmailAddress` = '$email'"; $sqlresult = mysql_query($checkSQL); $sqlrow = mysql_fetch_row($sqlresult); <<-- THIS IS LINE 109 -->> if ($sqlrow['CountOfRows'] == 0) { $IsUnique = true; } else { $registerMessage = "This email address is already registered"; } What I have tried to find out what is wrong: 1.) If I change the following line $sqlresult = mysql_query($checkSQL); to this $sqlresult = mysql_query($checkSQL) or die(mysql_error()); then I get the following message Query was empty when I echo the $checkSQL and copy it from the screen and run it in phpMyAdmin it run OK and returns CountOfRows = 2 The SQL statement generated looks like this SELECT COUNT(`EmailAddress`) AS `CountOfRows` FROM `printerclient` WHERE `EmailAddress` = 'test@test.com' I do not know what is wrong, can somebody help? Thanks. Peter.
Try to add a condition after your query : if($sqlresult) query else error_handling If it stays in the query branch, the problem is not coming from your query. Usually your error is in your SQL Statement. Try echo($checkSQL) and put the SQL into phpMyAdmin or any SQL program(you will have the real command sent to the server) Your problem might also be related to the rights of the database's user.
Thanks for your reply, but if you read my post you will see that my query does work in phpMyAdmin. I have already echoed it out and tested it. Any other suggestions? Peter.