|
Posted by Jerry Stuckle on 02/11/06 04:37
chuy08@gmail.com wrote:
> Basically I am using PHP 5.1.2 with Apache 2.0.5 on a FreeBSD 5.4 box
> with Mysql 4.1.1 running.
>
> I am attempting to write information to a Mysql table called Jabber. I
> can connect successfully, query data, and write data pretty much
> without problem. My problem is this.
>
> I am trying to do some duplicate checking on this table so I query the
> dbase with the following:
>
> /* Searching for username in Authreg database and assiging it to
> variable */
> $query1 = "SELECT * FROM `$table` WHERE username='$username'";
> $query1_results = mysql_query($query1) or die("Query Failed");
> $existing = mysql_result($query1_results, 0,0);
>
> Problem is this.
>
> When a user already exsits in database I have a conditional if
> statement that looks like such:
>
> /* Conditional statement that searches for exsiting username */
> if ($username == $existing) {
> die ("Please select a unique username");
> } else {
> ...
> }
>
> And it errorr out telling me to, "Please select a unique username" as
> stated above.
>
> When I am adding a new user to the database above I get the following
> error in my logs or in the browser depending on what --display-errors=
> is set to in my php.ini.:
>
> Warning: mysql_result() [function.mysql-result]: Unable to jump to row
> 0 on MySQL result index 4 in /usr/local/www/sfg/add_jabber/add_test.php
> on line 38
>
> I know this error is happening as a result of the following line when
> the user is not present in the database:
>
> $existing = mysql_result($query1_results, 0,0);
>
> So how would I write something that is conditional to test if the name
> exsits in the database before allowing me to write to the various
> tables. Any help appreciated.
>
Check to see how many rows are returned. If the username doesn't exist
in the database, MySQL won't return anything.
Also - always check to see if result is not false!
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|