Jump to content

[SOLVED] mysql help


aim25

Recommended Posts

<?php
        $dbHost = 'localhost';
        $dbUser = 'AIM25';
        $dbName = 'dbuser';
        $dbPass = '********';

	$dbLink = mysql_connect($dbHost, $dbUser, $dbPass);
        if(!$dbLink) die("Could not connect to database. " . mysql_error());
        mysql_select_db($dbName);

	$queryNameCheck = mysql_query("SELECT * FROM members WHERE userid = '$userName'", $dbLink);

	$intNamesInUse = mysql_num_rows($queryNameCheck);
	echo $intNamesInUse;
?>

 

when i run that i get:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource.

 

not sure how to fix it but i think its $queryNameCheck. Please help.

Link to comment
Share on other sites

Try it like this

<?php
        $dbHost = 'localhost';
        $dbUser = 'AIM25';
        $dbName = 'dbuser';
        $dbPass = '********';

	$dbLink = mysql_connect($dbHost, $dbUser, $dbPass);
        if(!$dbLink) die("Could not connect to database. " . mysql_error());
        
        mysql_select_db($dbName);

	$queryNameCheck = mysql_query("SELECT * FROM members WHERE userid = '$userName'");

	$intNamesInUse = mysql_num_rows($queryNameCheck);
	echo $intNamesInUse;

?>

 

Link to comment
Share on other sites

Holy.  Crap.  ANOTHER post where they don't add "or die(mysql_error());" to debug their queries.  It highlights the problem for you!  It's like a huge, neon sign with an arrow saying "HERE I AM".  =/

 

$queryNameCheck = mysql_query("SELECT * FROM members WHERE userid = '$userName'") OR die(mysql_error());

 

...

Link to comment
Share on other sites

well if you're not getting your die message from your connect, then you must be connecting okay.  Add a die to your select_db see if that gives you an error (spelled right? does it exist?)

 

also add a die to your mysql_query it should tell you something helpful as well.

 

Also, i don't see where $userName is actually being assigned anything, so you may be connecting proper and all but it's returning nothing, causing your num_rows to fail.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.