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
https://forums.phpfreaks.com/topic/111201-solved-mysql-help/
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
https://forums.phpfreaks.com/topic/111201-solved-mysql-help/#findComment-570745
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
https://forums.phpfreaks.com/topic/111201-solved-mysql-help/#findComment-570749
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
https://forums.phpfreaks.com/topic/111201-solved-mysql-help/#findComment-570750
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.