MySQL query error ? :/

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
KyleKatarN
Forum Newbie
Posts: 4
Joined: Thu Dec 08, 2005 11:36 am

MySQL query error ? :/

Post by KyleKatarN »

Hi I'm new to these forums and I won't really just start a thread and then never visit this site again - so I guess you won't get rid of me just yet! :D
Well my problem is, that I have like and "index" page, and there are different layout cells on it and on <5 of these cells there's a query that will select * from the database.
(The queries are for selecting the latest news, forum posts, blogs, etc, and for log in)
Though here the problem occur.
Sometimes it doesn't work and I have put on the error message so it says that no database is selected..
But if you refresh the page some times it works..
So I was wondering if you guys could help me with this?
Thanks..
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

well we need to see code:-D go read the "before posting in this forum.." thread first, all of it. then post your code :-D
KyleKatarN
Forum Newbie
Posts: 4
Joined: Thu Dec 08, 2005 11:36 am

ops

Post by KyleKatarN »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


sorry 

well first it includes the config file (with the database name, password, etc.. you get it)

this is uhm.. the config file

Code: Select all

$hostname_mysql = "localhost";
$database_mysql = "test";
$username_mysql = "root";
$password_mysql = "";
$mysql = mysql_connect($hostname_mysql, $username_mysql, $password_mysql) or trigger_error(mysql_error(),E_USER_ERROR);
then this is the news query..

Code: Select all

$getnewsquery = mysql_query("SELECT * FROM news ORDER BY ID DESC LIMIT 5");
	 while($gnr = mysql_fetch_array($getnewsquery)){
	 $gnrid = $gnr['ID'];
	 $gnrname = $gnr['title'];
	 echo "<small><i>(#$gnrid)</small></i><b> <a href=\"../index.php?view=single&id=$gnrid\">$gnrname</a><br></b>";
	 }
and THIS is the "if logged in" query! its quite big and such.. maybe its an error in this one because the error triggers on that layout cell..

Code: Select all

}
else
{
$user = $_SESSION['MM_Username'];
$userquery = mysql_query("SELECT * FROM users WHERE username = '".$user."'") or die(mysql_error());
while($r=mysql_fetch_array($userquery))
{
$level = $r['level'];
echo "Username: <b><a href=\"../profile.php?user=".$_SESSION['MM_Username']."\">".$_SESSION['MM_Username']."</a></b> ";
echo "| Level: <b><a href=\"../users/list.php?list=$level\">$level</a></b> | <b><a href=\"../users/edit.php\">Edit Settings </a></b>|";
if($level == 'Admin'){
echo " <a href=\"../add_news.php\"><br>Add News</a> </b>|";
echo " <a href=\"../adminconfig.php\">Admin Area</a> |";
}
?>
    <a href="<?php echo $logoutAction ?>">Logout</a>
  <? }
}
(the other code above is the "logout code" (a 'dreamweaver code'..))


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

where does it have

Code: Select all

mysql_select_db('database_name_here');
?
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

KyleKatarn is a cool name. Would you treat me real well if I changed my name to Jan Ors? LOL
KyleKatarN
Forum Newbie
Posts: 4
Joined: Thu Dec 08, 2005 11:36 am

Post by KyleKatarN »

OFCOURSE hahhaa :P
well i think i was a bit too careless when i started the thread, cause the solution was a quite simple one..
i kinda use 2 connection files (yes i know seems stupid :P) and i didnt include one of them.. :DD
now it works.. thanks though ^^ and sorry for not using [syntax=php][/syntax]
Post Reply