Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

No database selected

Hello, i have an PHP script on my linux dedicated server and when i try to run the php script in the browser i get this error "No database selected". But i do select the database in the code.

<?php
$con=mysql_pconnect("178.32.221.208","hug","xxxxxx");
mysql_select_db("sharp");

$usr = mysql_real_escape_string($_GET['usr']);
$ip = escapeshellcmd($_POST['ip']);
$port = escapeshellcmd($_POST["port"]);
$size = escapeshellcmd($_POST["size"]);
$time = escapeshellcmd($_POST["time"]);
$est = time() + $time;
$c = mysql_query("SELECT * FROM members WHERE package >= '$time' AND thread >=             '$size' AND username='$usr'") or die(mysql_error());
 if(mysql_num_rows($c) == '1') {
mysql_query("INSERT INTO table (ip, port, time, size, usr, est)
VALUES ('$ip', '$port', '$time', '$size', '$usr', '$est')");
 $res = mysql_query("SELECT * FROM table WHERE est='$est'") or die(mysql_error());
while($a = mysql_fetch_array($res))
  {
    $id = $a['id'];
header('Location: c?id='.$id);
}
}
else{
    header('Location: hub?error=much');
}
?>

4 Answers

Yes it does. I have the same code on another server and it works flawless there.

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

It sounds to me like it's not connecting at all. Do you have access to the server to try to connect to MySQL from the command line?

Can you connect to the database using those credentials using the command line mysql utility?