Page 1 of 1

Noob question (No database selected)

Posted: Thu Aug 27, 2009 11:32 pm
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.

Re: Noob question (No database selected)

Posted: Thu Aug 27, 2009 11:42 pm
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";

Re: Noob question (No database selected)

Posted: Fri Aug 28, 2009 12:47 am
by Psythik
Ah, I knew it was gonna be something blatantly obvious. :banghead:

Thank you.