Noob question (No database selected)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Psythik
Forum Newbie
Posts: 2
Joined: Thu Aug 27, 2009 11:26 pm

Noob question (No database selected)

Post by Psythik »

I'm trying to install a poll script. I created a database for it in cPanel:

Database name: psythik_poll
Database user: psythik_poll
Database user pass: aaaaaa (not really, but you know what I mean)

The poll script uses the following code to connect to the db:

Code: Select all

<?php
$db = mysql_connect("localhost", "psythik_poll", "aaaaaa") or die("Could not connect.");
if(!$db) 
    die("no db");
if(!mysql_select_db("db_name",$db))
    die("No database selected.");
Obviously I'm missing something here, because No database selected comes up when I try to run the script. I have very limited knowledge (read: none whatsoever) of PHP & mySQL, so if anyone could help me out by describing the solution in layman's terms, I'd appreciate it.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Noob question (No database selected)

Post by Zoxive »

Change "db_name" to "psythik_poll"

You can also echo out the error and error number.

Code: Select all

echo mysql_errno($db) . ": " . mysql_error($db). "\n";
Psythik
Forum Newbie
Posts: 2
Joined: Thu Aug 27, 2009 11:26 pm

Re: Noob question (No database selected)

Post by Psythik »

Ah, I knew it was gonna be something blatantly obvious. :banghead:

Thank you.
Post Reply