Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Nitro
Forum Newbie
Posts: 5
Joined: Sun Jul 13, 2003 11:49 am
Location: London, England

Question

Post by Nitro »

Code: Select all

$query = mysql_query("SELECT username FROM verify, username FROM account WHERE username='$username'");
	$num = mysql_num_rows($query);
Can anyone please tell me why that doesnt work, and how I can make it work.

Thanks,
Last edited by Nitro on Mon Jul 28, 2003 9:54 am, edited 1 time in total.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

What's the error message?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

...

Post by kettle_drum »

You probably need to suggest which username field you want to select. I.e. SELECT username.table_name FROM
Nitro
Forum Newbie
Posts: 5
Joined: Sun Jul 13, 2003 11:49 am
Location: London, England

Post by Nitro »

Here is the error message:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/nitro/public_html/signup.php on line 95
User avatar
mikusan
Forum Contributor
Posts: 247
Joined: Thu May 01, 2003 1:48 pm

Post by mikusan »

I have had that annoying pointless error for the longest amount of time. It is related to the rest of the code and not only those 2 lines... you need to show us more code especially if you have an if statement somewhere there because that's where my problem arose.

I think with more code we can help you.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You've got 2 FROM clauses in that SQL statement. It looks like you'll probably have some other problems with it too so try this, which should give you a better, MySQL generated, error:

Code: Select all

$sql = "SELECT username FROM verify, username, account WHERE verify.username = '$username'";
$query = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
Mac
Nitro
Forum Newbie
Posts: 5
Joined: Sun Jul 13, 2003 11:49 am
Location: London, England

Here is the whole thing:

Post by Nitro »

Code: Select all

$query = mysql_query("SELECT username FROM verify, username FROM account WHERE username='$username'");
	$num = mysql_num_rows($query);
	if ($num > 0)
	&#123;
	echo "<center><b>Error!</b> The username "$username" is already in use. Please try a differant one.";
	form();
	exit();
	&#125;
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Did you try the code snippet I posted?

Mac
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post by Drachlen »

Code: Select all

<?php
$result = mysql_query("SELECT a.* FROM `verify` as a, `account` as b WHERE a.username = '$username' AND b.username = '$username'") or die ("b0rked: ".mysql_error());
if (mysql_num_rows($result) >= 1) {
?>
Tested to an extent, should work...
Post Reply