homepage Welcome to WebmasterWorld Guest from 54.205.59.78
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Warning:mysql select db() expects parameter 2 to be boolean
I am receiving warning :mysql_select_db() expects parameter 2 to be boolean
sonya krishna




msg:4618279
 4:29 am on Oct 22, 2013 (gmt 0)

I am developing a software for online test in PHP for mobile phones.While, running question.php in windows ,I am getting
warning:select_mysql_db() expects parameter 2 to be resource ,boolean given in C://wamp/www/student/question.php on line 254.
The line number 254 is $db_result = mysql_select_db($database, $con) in my PHP code. Also I am getting:warning mysql_fetch_assoc() expects parameter 1 to be resource ,boolean given in C://wamp/www/student/question.php on line 367.The line number 367 is $sqlArr = mysql_fetch_assoc($sqlQuer).
My PHP code is given below.Any one please help me to solve this.Thanks in advance.

PHP Code

$user_name = "root";
$password = "root";
$database = "mydatabase";
$server = "localhost";
$con = mysql_connect($server, $user_name, $password);
$db_result = mysql_select_db($database, $con);

$sql = sprintf(
"SELECT * FROM question WHERE name = '%s'", mysql_real_escape_string($h)
);

$sqlQuer = mysql_query($sql);

$sqlArr = mysql_fetch_assoc($sqlQuer);

 

brotherhood of LAN




msg:4618280
 4:33 am on Oct 22, 2013 (gmt 0)

Welcome to the forums sonya krishna,

It sounds like the errors are a result of no connection being established to the MySQL server at all, and since you have no warning/error checking, the script continues to show more warning messages.

Try changing it to
$con = mysql_connect($server, $user_name, $password) or die(mysql_error());

It should give you a more verbose reason as to why the server could not be connected to, usually it's because the server isn't where you specified it should be, or the username/password is wrong.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved