[PHP] PHP/MySQL Code

2001-04-06 Thread Jeff Oien

This code won't work. I'm trying to get an error if the username
is entered incorrectly but it won't go through the if brackets. I even
tried printing out $num and it's 0. I also tried 
if ($num = "0") {
if ($num = '0') {

?php
include("connect.php");
$result=mysql_query("select * from table where
username='$username'",$connection) or die ("Can't do it");
$num = mysql_numrows($result);

if ($num = 0) {
print "htmlerror message etc.
exit;
}

Jeff Oien

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP/MySQL Code

2001-04-06 Thread Steve Werby

"Jeff Oien" [EMAIL PROTECTED] wrote:
 This code won't work. I'm trying to get an error if the username
 is entered incorrectly but it won't go through the if brackets. I even
 tried printing out $num and it's 0. I also tried
 if ($num = "0") {
 if ($num = '0') {

The single "=" sets the variable $num to that value.  A double "==" is an
equality comparison operator - that's what you want in this case.  Also,
since mysql_numrows() returns a number, not a string, you don't need quots
around the 0.

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] PHP/MySQL Code

2001-04-06 Thread Jon Haworth

The comparison operator is ==. = means "assign". Try:

if ($num == 0) {
foo(bar, baz);
}

AFAIK what your code means is "assign 0 to $num and then, if that worked,
print the error message."

HTH
Jon


-Original Message-
From: Jeff Oien [mailto:[EMAIL PROTECTED]]
Sent: 06 April 2001 17:51
To: PHP
Subject: [PHP] PHP/MySQL Code 


This code won't work. I'm trying to get an error if the username
is entered incorrectly but it won't go through the if brackets. I even
tried printing out $num and it's 0. I also tried 
if ($num = "0") {
if ($num = '0') {

?php
include("connect.php");
$result=mysql_query("select * from table where
username='$username'",$connection) or die ("Can't do it");
$num = mysql_numrows($result);

if ($num = 0) {
print "htmlerror message etc.
exit;
}

Jeff Oien

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



**
'The information included in this Email is of a confidential nature and is 
intended only for the addressee. If you are not the intended addressee, 
any disclosure, copying or distribution by you is prohibited and may be 
unlawful. Disclosure to any party other than the addressee, whether 
inadvertent or otherwise is not intended to waive privilege or
confidentiality'

**

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP/MySQL Code

2001-04-06 Thread Brian S. Dunworth

At 11:51 AM 4/6/01 -0500, Jeff Oien wrote:

if ($num = 0) {
 print "htmlerror message etc.
 exit;
}

   This "conditional" will always run.  you are assigning $num the value of 
zero within your if() statement, and that assignation actually happens, so 
the result is "true" and the braced statements run.

   Try:

if ($num == 0) {
   print "blah blah blah, etc.\n"
   exit;
}

  - Brian

  -
Brian S. Dunworth
Sr. Software Development Engineer
Oracle Database Administrator
The Printing House, Ltd.

(850) 875-1500  x225
[EMAIL PROTECTED]
  -


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] PHP/MySQL Code

2001-04-06 Thread Jeff Oien

 "Jeff Oien" [EMAIL PROTECTED] wrote:
  This code won't work. I'm trying to get an error if the username
  is entered incorrectly but it won't go through the if brackets. I even
  tried printing out $num and it's 0. I also tried
  if ($num = "0") {
  if ($num = '0') {
 
 The single "=" sets the variable $num to that value.  A double "==" is an
 equality comparison operator - that's what you want in this case.  Also,
 since mysql_numrows() returns a number, not a string, you don't need quots
 around the 0.
 
 --
 Steve Werby
 President, Befriend Internet Services LLC
 http://www.befriend.com/

Ah, one of those repeated rookie mistakes. Thanks for helping me out.
Jeff Oien

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP/MySQL Code

2001-04-06 Thread long huynh

I think the function should be mysql_num_rows.  There's an mSQL function
msql_numrows, but for MySQL it needs the second underscore in between 'num'
and 'rows'.

 $num = mysql_numrows($result);


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP/MySQL Code

2001-04-06 Thread Steve Werby

"long huynh" [EMAIL PROTECTED] wrote:
 I think the function should be mysql_num_rows.  There's an mSQL function
 msql_numrows, but for MySQL it needs the second underscore in between
'num'
 and 'rows'.

  $num = mysql_numrows($result);

Either will work.  mysql_numrows() is the old name of the function from
previous PHP versions.

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]