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.

This is strange. But one thing.

$sqlrow = mysql_fetch_row($sqlresult); <<-- THIS IS LINE 109 -->>
if ($sqlrow == 0) {

You have used mysql_fetch_row. It returns rows as numeric array . So, you can't give, $sqlrow. You can use mysql_fetch_array instead. I am not sure if this will help, but remove ` from your query !

THANKS, THANKS, THANKS ...
using mysql_fetch_array($sqlresult, MYSQL_NUM) did the trick.

It still is a mystery why the original code did not work however using mysql_fetch_array did work.

Removing of ' did not work, whether they are there or not the use of mysql_fetch_row was the problem, if any body knows why please point me to documentation that may help me understand. The PHP docs does not give me enough info to understand why?

Thank you.

Peter.

I am not really sure why you got "Query was empty" message. :-O

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.