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
Lucas Andersson
1,614 PointsNo 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
Andrew Chalkley
Treehouse Guest TeacherDoes the database k0vir_sharp exist?
Lucas Andersson
1,614 PointsYes it does. I have the same code on another server and it works flawless there.
Randy Hoyt
Treehouse Guest TeacherIt 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?
James Barnett
39,199 PointsCan you connect to the database using those credentials using the command line mysql utility?