Page 1 of 1
MySQL query error ? :/
Posted: Thu Dec 08, 2005 11:41 am
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!

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..
Posted: Thu Dec 08, 2005 11:44 am
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

ops
Posted: Thu Dec 08, 2005 11:56 am
by KyleKatarN
Jcart | Please use 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
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Thu Dec 08, 2005 11:58 am
by John Cartwright
where does it have
Code: Select all
mysql_select_db('database_name_here');
?
Posted: Thu Dec 08, 2005 2:44 pm
by BDKR
KyleKatarn is a cool name. Would you treat me real well if I changed my name to Jan Ors? LOL
Posted: Tue Dec 13, 2005 1:45 pm
by KyleKatarN
OFCOURSE hahhaa

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

) and i didnt include one of them.. :DD
now it works.. thanks though ^^ and sorry for not using [syntax=php][/syntax]