no database selected

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Post Reply
peterachutha
New php-forum User
New php-forum User
Posts: 10
Joined: Sat May 31, 2014 10:35 pm

Re: no database selected

Post by peterachutha » Fri Jun 06, 2014 3:55 pm

My guess is that you may have forgotten to connect to your database. You would probably need to add something like the code below before you create tables.


$host = "localhost";
$user = "myusername";
$pass = "mypassword";

$myconn = mysql_connect($host, $user, $pass);

if (!$myconn) {
echo "Could not connect to server\n";

} else {
echo "Connection established\n";

mysql_select_db( 'myusername' );

CREATE TABLE IF NOT EXISTS `bahagian` ( ....
.
.
.
}

I have dropped code such as "ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2" as it was complicating my programming. You can try without it and then add them back later.

Do take a look at the php manual at: http://www.php.net/manual/en/function.m ... ect-db.php as this will be very helpful.

peterachutha
New php-forum User
New php-forum User
Posts: 10
Joined: Sat May 31, 2014 10:35 pm

Re: no database selected

Post by peterachutha » Sat Jun 07, 2014 10:20 am

You dengan kerajaan Malaysia? (Are you with the Malaysian Government?) Sebab you punya code, tengok macham dari Bank negara atau lain pentadbiran. (Because your code looks like form Bank Negara (Central Bank) of similar administration.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests