André,

Thank you for your patience, solution one works fine.

Regards
Col
"André cerqueira" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> i think the query: "SELECT count(uid) FROM users WHERE
> username='$username'", will give a one row result, that row will have
> one field, and that field is the number of rows that match the where
> clause (you are using count(uid))
> if there is no match, the result will be a row, with a field, with 0 as
> value
>
> mysql_num_rows return the number of rows of the given result
>
> you can do this:
> > $result = mysql_query("SELECT count(uid) FROM users WHERE username =
'$username'")
>  >     or die("Invalid query: " . mysql_error());
> > $num_rows = mysql_result($result, 0, 0);
>
> or this:
> > $result = mysql_query("SELECT uid FROM users WHERE username =
'$username'")
>  >     or die("Invalid query: " . mysql_error());
> > $num_rows = mysql_num_rows($result);
>
> i think the first one is better
>
>
> Petcol wrote:
> > Andre,
> >
> > Thank you, I had read the manual, understanding it fully when you've
> >  been coding in another language is another matter.
> >
> > I had relied on DreamweaverMX to create the Database connection which
> >
> >
> >
> meant
> > I didn't really understand how it was returning the results.
> >
> > I was able to output the results by altering the code DreamweaverMX
> > had created.
> >
> > Thanks, now using the database query method you showed, I've been
> > able to get the number of rows returned.
> >
> > However, whenever I change the username I still get a row count of 1
> >  ? <?php if (isset($_POST["USERNAME"])) { $username =
> > $_POST["USERNAME"];
> >
> > $result = mysql_query("SELECT count(uid) FROM users WHERE username =
> > '$username'") or die("Invalid query: " . mysql_error()); $num_rows =
> > mysql_num_rows($result); echo $username ."&nbsp;&nbsp;\n". $num_rows;
> > } ?>
> >
> > echo $username returns the username entered into the field before the
> >  submit button
> is hit.
> > $num_rows; always returns one numeric 1 even though there is no
> > username like
> $username
> > in the database ??????
> >
> > Have I missed something?
> >
> > Col
> >
> > "André cerqueira" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> >
> > I believe you forgot to read the manual.
> >
> >
> >> $query_qUsername = "SELECT * FROM users WHERE username =
> >> '$username'"; $num_rows = mysql_num_rows($query_qUsername);
> >
> >
> > $query_qUsername is a String
> >
> > mysql_num_rows want a result resource as argument You have no result
> >  till you do mysql_query
> >
> >
> > Read these please: http://www.php.net/mysql
> > http://www.php.net/mysql_query
> >
> >
> >
> > Petcol wrote:
> >
> >> PHP Newbie,
> >
> >> I'm trying to find out if a username already appears in my
> >> database.
> >
> >> I have two users in my table, one is colin so when I enter a
> >> username of colin I would normally under ColdFusion anyway just to
> >>  something like: <cfif $query_qUsername.RecordCount GT 0> User
> >> already exists do something else, like throw the user back an
> >
> >> error.
> >
> >> </cfif>
> >
> >> My Query works $query_qUsername = "SELECT * FROM users WHERE
> >> username = '$username'";
> >
> >> I've tried a number of different things here and everything either
> >>  comes back with nothing, or throws an error. $num_rows =
> >> mysql_num_rows($query_qUsername); echo $num_rows; // this comes
> >> back with nothing, I was expecting a
> >
> >> numeric
> >
> >> of 1 exit;
> >
> >> Regards Col
> >
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.4 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFAMFIhaxdA/5C8vH8RAocmAKCiJsq+ZjfwKT8+Nh/AbNQ9vB5ZOwCeKCRd
> hKO0x1rckabl8/++P995sCE=
> =2epc
> -----END PGP SIGNATURE-----

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to