Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-17-2011, 08:16 AM   PM User | #1
johnmergene
New to the CF scene

 
Join Date: Mar 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
johnmergene is an unknown quantity at this point
Unhappy Error: No database selected

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>?
johnmergene is offline   Reply With Quote
Old 07-17-2011, 03:35 PM   PM User | #2
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
you have the line that selects the database commented out:
//mysql_select_db("accounts",$con);
guelphdad is offline   Reply With Quote
Reply

Bookmarks

Tags
database, error

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:05 PM.


Advertisement
Log in to turn off these ads.