Home > Archive > PHP Language > December 2006 > Warning: mysql_num_rows(): supplied argument is not a valid MySQL
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Warning: mysql_num_rows(): supplied argument is not a valid MySQL
|
|
| jay2006 2006-12-21, 3:58 am |
| Hi,
I keep getting this error after registration, does anyone know the fix?
Thanks.
Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in /insert.php on line 117
Warning: Cannot modify header information - headers already sent by
(output started at /insert.php:117)
in /insert.php on line 128
Warning: Cannot modify header information - headers already sent by
(output started at /insert.php:117)
in /insert.php on line 129
if($num3 != 0)
{
$msg = ("<b>Email Already Registered:</b><br>We are sorry but the
email you have entered has already been registered, please use another
or try to recover your previous account.");
mysql_close($link);
}
else
{
$sql = mysql_query("SELECT C_USER_NAME FROM CUSTOMER where
C_USER_NAME = '$cus[8]'", $link);
line 117>>> $num = mysql_num_rows($sql);
if($num != 0)
{
$msg = ("<b>Username Already In Use:</b><br>We are sorry but the
username you have chosen has already been taken. Please go back and try
another or add numbers to make it unique.");
mysql_close($link);
}
else
{
mysql_query("INSERT INTO customer (C_TITLE, C_FNAME, C_SNAME,
C_ADDRESS, C_ADDRESS2, C_TOWN, C_COUNTY, C_PCODE, C_TEL_NUM, C_EMAIL,
C_PWORD, C_USER_NAME, C_KEY, C_SECRET_A, C_SECRET_Q, C_MAIL_TYPE)
values
(UPPER('$cus[0]'),UPPER('$cus[1]'),UPPER
('$cus[2]'),UPPER('$cus[3]'),UPPER('$add
2'),UPPER('$cus[4]'),UPPER('$cus[5]'),UP
PER('$cus[6]'),'$cus[7]',LOWER('$email')
,'$pword','$cus[8]','$cUsername','$cus[1
0]','$cus[9]','$type')",
$link);
mysql_close($link);
setcookie("key:", $cUsername, time()+300); // sets cookie
header("Location: activate.php"); // directs to activation script*/
}
}
}
| |
| Geoff Berrow 2006-12-21, 3:58 am |
| Message-ID: <1166682191.046574.280090@f1g2000cwa.googlegroups.com> from
jay2006 contained the following:
>Warning: mysql_num_rows(): supplied argument is not a valid MySQL
>result resource in /insert.php on line 117
Your query is failing
>
>Warning: Cannot modify header information - headers already sent by
>(output started at /insert.php:117)
>in /insert.php on line 128
>
>Warning: Cannot modify header information - headers already sent by
>(output started at /insert.php:117)
>in /insert.php on line 129
These are created because php has echoed a warning before your header
call
>
>
> if($num3 != 0)
> {
> $msg = ("<b>Email Already Registered:</b><br>We are sorry but the
>email you have entered has already been registered, please use another
>or try to recover your previous account.");
> mysql_close($link);
> }
> else
> {
> $sql = mysql_query("SELECT C_USER_NAME FROM CUSTOMER where
>C_USER_NAME = '$cus[8]'", $link);
>line 117>>> $num = mysql_num_rows($sql);
Do this:
$s=SELECT C_USER_NAME FROM CUSTOMER where C_USER_NAME = '$cus[8]'";
$sql = mysql_query($s, $link);
That way your can debug the SQL statement by doing
echo $s;
Also you can do this which gives you more info
$sql = mysql_query($s, $link) or die(mysql_error());
You haven't shown your database connection section. Is that ok, did you
remember to include it?
--
Geoff Berrow 0110001001101100010000000110
0011011010110110010001101111011001110010
11
1001100011011011110010111001110101011010
11
| |
| jay2006 2006-12-21, 3:58 am |
| Oops, sorry, I thought to just add the error parts. I'll give what you
said a go and will let you know how it goes.
Thanks
Geoff Berrow wrote:
> Message-ID: <1166682191.046574.280090@f1g2000cwa.googlegroups.com> from
> jay2006 contained the following:
>
>
> Your query is failing
>
> These are created because php has echoed a warning before your header
> call
>
>
> Do this:
> $s=SELECT C_USER_NAME FROM CUSTOMER where C_USER_NAME = '$cus[8]'";
> $sql = mysql_query($s, $link);
>
> That way your can debug the SQL statement by doing
> echo $s;
>
> Also you can do this which gives you more info
> $sql = mysql_query($s, $link) or die(mysql_error());
>
> You haven't shown your database connection section. Is that ok, did you
> remember to include it?
>
>
> --
> Geoff Berrow 0110001001101100010000000110
> 0011011010110110010001101111011001110010
11
> 1001100011011011110010111001110101011010
11
| |
| jay2006 2006-12-21, 3:58 am |
| I added:
$s=SELECT C_USER_NAME FROM CUSTOMER where C_USER_NAME = '$cus[8]'";
$sql = mysql_query($s, $link);
Then tried to register and got the following error:
Parse error: syntax error, unexpected T_STRING in
/home/squirt/public_html/mature/files/insert.php on line 116
jay2006 wrote:[color=darkred]
> Oops, sorry, I thought to just add the error parts. I'll give what you
> said a go and will let you know how it goes.
>
> Thanks
>
>
>
> Geoff Berrow wrote:
| |
|
| "jay2006" <tigersta@iinet.net.au> wrote in message
news:1166685440.527064.274260@i12g2000cwa.googlegroups.com...
>I added:
>
>
> $s=SELECT C_USER_NAME FROM CUSTOMER where C_USER_NAME = '$cus[8]'";
> $sql = mysql_query($s, $link);
>
>
> Then tried to register and got the following error:
>
>
> Parse error: syntax error, unexpected T_STRING in
> /home/squirt/public_html/mature/files/insert.php on line 116
You both forgot the first quote around the $s variable.
$s = "SELECT C_USER_NAME FROM CUSTOMER WHERE C_USER_NAME = '$cus[8]'"
-Lost
| |
| jay2006 2006-12-21, 7:58 am |
| OK, i tried it with the quote in, and got this error:
Parse error: syntax error, unexpected T_VARIABLE in
/home/squirt/public_html/mature/files/insert.php on line 117
$s = "SELECT C_USER_NAME FROM CUSTOMER WHERE C_USER_NAME = '$cus[8]'"
line 117 >>>> $sql = mysql_query($s, $link);
-Lost wrote:
> "jay2006" <tigersta@iinet.net.au> wrote in message
> news:1166685440.527064.274260@i12g2000cwa.googlegroups.com...
>
> You both forgot the first quote around the $s variable.
>
> $s = "SELECT C_USER_NAME FROM CUSTOMER WHERE C_USER_NAME = '$cus[8]'"
>
> -Lost
| |
| Geoff Berrow 2006-12-21, 7:58 am |
| Message-ID: <1166695793.854577.17810@f1g2000cwa.googlegroups.com> from
jay2006 contained the following:
>OK, i tried it with the quote in, and got this error:
>
>Parse error: syntax error, unexpected T_VARIABLE in
>/home/squirt/public_html/mature/files/insert.php on line 117
>
>
>
>$s = "SELECT C_USER_NAME FROM CUSTOMER WHERE C_USER_NAME = '$cus[8]'"
>line 117 >>>> $sql = mysql_query($s, $link);
Missing semi-colon
$s = "SELECT C_USER_NAME FROM CUSTOMER WHERE C_USER_NAME = '$cus[8]'";
$sql = mysql_query($s, $link);
--
Geoff Berrow 0110001001101100010000000110
0011011010110110010001101111011001110010
11
1001100011011011110010111001110101011010
11
| |
| jay2006 2006-12-21, 7:58 am |
| Yeah! thnx for your help guys!! It works now. Appreciate :)
Geoff Berrow wrote:
> Message-ID: <1166695793.854577.17810@f1g2000cwa.googlegroups.com> from
> jay2006 contained the following:
>
>
> Missing semi-colon
>
> $s = "SELECT C_USER_NAME FROM CUSTOMER WHERE C_USER_NAME = '$cus[8]'";
> $sql = mysql_query($s, $link);
> --
> Geoff Berrow 0110001001101100010000000110
> 0011011010110110010001101111011001110010
11
> 1001100011011011110010111001110101011010
11
| |
|
| "Geoff Berrow" <blthecat@ckdog.co.uk> wrote in message
news:ocoko2to3pavr6sh2k2skbok2eqs0fbme1@
4ax.com...
> Message-ID: <1166695793.854577.17810@f1g2000cwa.googlegroups.com>
> Missing semi-colon
HAHA! Maybe together we can make a somewhat literate programmer!
Be well, Geoff.
-Lost
| |
| Geoff Berrow 2006-12-21, 7:58 am |
| Message-ID: <lISdnTU8k6Ew-BfYnZ2dnUVZ_smonZ2d@comcast.com> from -Lost
contained the following:
>
>
>HAHA! Maybe together we can make a somewhat literate programmer!
Heh, but the semi-colon wasn't missing in the one you corrected. But
really the OP needs to learn to debug simple stuff like this. I used to
tell my beginner students that they will be glad to see parse errors
because it means that PHP is telling you something is wrong. Much worse
than that is when the program runs without error, but not as you expect.
>
>Be well, Geoff.
You too. I am fine, but my dog has been ill. Mail me if you want to
know more.
--
Geoff Berrow 0110001001101100010000000110
0011011010110110010001101111011001110010
11
1001100011011011110010111001110101011010
11
| |
|
| On 20 Dec 2006 22:23:11 -0800, "jay2006" <tigersta@iinet.net.au> wrote:
>Hi,
>
>I keep getting this error after registration, does anyone know the fix?
>Thanks.
>
>
>Warning: mysql_num_rows(): supplied argument is not a valid MySQL
>result resource in /insert.php on line 117
>
>Warning: Cannot modify header information - headers already sent by
>(output started at /insert.php:117)
>in /insert.php on line 128
>
>Warning: Cannot modify header information - headers already sent by
>(output started at /insert.php:117)
>in /insert.php on line 129
>
>
> if($num3 != 0)
> {
> $msg = ("<b>Email Already Registered:</b><br>We are sorry but the
>email you have entered has already been registered, please use another
>or try to recover your previous account.");
> mysql_close($link);
> }
> else
> {
> $sql = mysql_query("SELECT C_USER_NAME FROM CUSTOMER where
>C_USER_NAME = '$cus[8]'", $link);
>line 117>>> $num = mysql_num_rows($sql);
>
> if($num != 0)
> {
> $msg = ("<b>Username Already In Use:</b><br>We are sorry but the
>username you have chosen has already been taken. Please go back and try
>another or add numbers to make it unique.");
> mysql_close($link);
> }
> else
> {
> mysql_query("INSERT INTO customer (C_TITLE, C_FNAME, C_SNAME,
>C_ADDRESS, C_ADDRESS2, C_TOWN, C_COUNTY, C_PCODE, C_TEL_NUM, C_EMAIL,
>C_PWORD, C_USER_NAME, C_KEY, C_SECRET_A, C_SECRET_Q, C_MAIL_TYPE)
>values
> (UPPER('$cus[0]'),UPPER('$cus[1]'),UPPER
('$cus[2]'),UPPER('$cus[3]'),UPPER('$add
2'),UPPER('$cus[4]'),UPPER('$cus[5]'),UP
PER('$cus[6]'),'$cus[7]',LOWER('$email')
,'$pword','$cus[8]','$cUsername','$cus[1
0]','$cus[9]','$type')",
>$link);
> mysql_close($link);
> setcookie("key:", $cUsername, time()+300); // sets cookie
> header("Location: activate.php"); // directs to activation script*/
> }
> }
>}
If you are going to use an array variable inside a select query must be enclosed with
curly brackets {} and don't think you need that $link at the end
$sql = mysql_query("SELECT C_USER_NAME FROM CUSTOMER where C_USER_NAME = '{$cus[8]}' ");
or
$sql = mysql_query("SELECT C_USER_NAME FROM CUSTOMER where C_USER_NAME = ' ".$cus[8]." ' ");
also mysql connections are automatically closed when a page is finsihed processing.
mysql_close() closes the non-persistent connection to the MySQL server that's associated with the
specified link identifier. If link_identifier isn't specified, the last opened link is used.
Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed
at the end of the script's execution.
| |
| hackajar@gmail.com 2006-12-25, 7:58 am |
| $sql = mysql_query("SELECT C_USER_NAME FROM CUSTOMER where
C_USER_NAME = '$cus[8]'", $link);
Replace above with this:
$query = "SELECT C_USER_NAME FROM CUSTOMER where
C_USER_NAME = '".$cus[8]."';"; //NOTE: brack out of quotes when
referencing Array hash elemets ;)
$result = mysql_query($query) or die(mysql_error());
-Hackajar
jay2006 wrote:
> Hi,
>
> I keep getting this error after registration, does anyone know the fix?
> Thanks.
>
>
> Warning: mysql_num_rows(): supplied argument is not a valid MySQL
> result resource in /insert.php on line 117
>
> Warning: Cannot modify header information - headers already sent by
> (output started at /insert.php:117)
> in /insert.php on line 128
>
> Warning: Cannot modify header information - headers already sent by
> (output started at /insert.php:117)
> in /insert.php on line 129
>
>
> if($num3 != 0)
> {
> $msg = ("<b>Email Already Registered:</b><br>We are sorry but the
> email you have entered has already been registered, please use another
> or try to recover your previous account.");
> mysql_close($link);
> }
> else
> {
> $sql = mysql_query("SELECT C_USER_NAME FROM CUSTOMER where
> C_USER_NAME = '$cus[8]'", $link);
> line 117>>> $num = mysql_num_rows($sql);
>
> if($num != 0)
> {
> $msg = ("<b>Username Already In Use:</b><br>We are sorry but the
> username you have chosen has already been taken. Please go back and try
> another or add numbers to make it unique.");
> mysql_close($link);
> }
> else
> {
> mysql_query("INSERT INTO customer (C_TITLE, C_FNAME, C_SNAME,
> C_ADDRESS, C_ADDRESS2, C_TOWN, C_COUNTY, C_PCODE, C_TEL_NUM, C_EMAIL,
> C_PWORD, C_USER_NAME, C_KEY, C_SECRET_A, C_SECRET_Q, C_MAIL_TYPE)
> values
> (UPPER('$cus[0]'),UPPER('$cus[1]'),UPPER
('$cus[2]'),UPPER('$cus[3]'),UPPER('$add
2'),UPPER('$cus[4]'),UPPER('$cus[5]'),UP
PER('$cus[6]'),'$cus[7]',LOWER('$email')
,'$pword','$cus[8]','$cUsername','$cus[1
0]','$cus[9]','$type')",
> $link);
> mysql_close($link);
> setcookie("key:", $cUsername, time()+300); // sets cookie
> header("Location: activate.php"); // directs to activation script*/
> }
> }
> }
| |
|
| hackajar@gmail.com schrieb:
> $sql = mysql_query("SELECT C_USER_NAME FROM CUSTOMER where
> C_USER_NAME = '$cus[8]'", $link);
>
> Replace above with this:
> $query = "SELECT C_USER_NAME FROM CUSTOMER where
> C_USER_NAME = '".$cus[8]."';"; //NOTE: brack out of quotes when
> referencing Array hash elemets ;)
--> '".$cus[8]."'
I think you meant: '"' .$cus[8]. '"'
> $result = mysql_query($query) or die(mysql_error());
>
> -Hackajar
> jay2006 wrote:
>
| |
|
| Ric schrieb:
> hackajar@gmail.com schrieb:
>
>
> --> '".$cus[8]."'
>
> I think you meant: '"' .$cus[8]. '"'
Ah no your sql staement should be correct, I was just thinking about :
$query = 'SELECT C_USER_NAME FROM CUSTOMER where
C_USER_NAME = "' .$cus[8]. '";' ;
[color=darkred]
>
>
>
>
>
>
| |
| hackajar@gmail.com 2006-12-25, 6:58 pm |
| :) cought you off guard ;)
Hackajar
Ric wrote:[color=darkred]
> Ric schrieb:
>
> Ah no your sql staement should be correct, I was just thinking about :
>
>
> $query = 'SELECT C_USER_NAME FROM CUSTOMER where
> C_USER_NAME = "' .$cus[8]. '";' ;
>
>
|
|
|
|
|