...

View Full Version : Error: No database selected



johnmergene
07-17-2011, 09:16 AM
I have this code,

<?php
session_start();
if(!session_is_registered(myusername)){
$usnm = myusername;
header("location: login2.html");
}
$con = mysql_connect("xxxxxxxxx", "xxxxxxxx", "xxxxxxxx") or die(mysql_error());
$q = "SELECT * FROM accounts WHERE Name = '$usnm'";

//mysql_select_db("accounts",$con);
$result = mysql_query($q)or die ('Error: '.mysql_error ());
if( $result = mysql_query("SELECT * FROM accounts WHERE Name = '$usnm'")) {
if( mysql_num_rows( $result )){
$ress=mysql_fetch_assoc($result); }
}
while ($db_field = mysql_fetch_assoc($result)) {
print $db_field[ID] . "<BR>";
print $db_field['Name'] . "<BR>";
print $db_field['Age'] . "<BR>";;
}

//$name=$num_rows['Name'];
echo "<html>
<a href=logout.php>Logout</a>
</html>
";
?>



Then Error: No database selected appeared.,
What is the problem of my code?
CAn someone help me>?

guelphdad
07-17-2011, 04:35 PM
you have the line that selects the database commented out:
//mysql_select_db("accounts",$con);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum