FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


MySQL - Session error?





HeavyVanilla
I've been strugling with this problem for some time now, and i don't really know what to look for/try to correct.

I've made this login, and the login works fine and everything. The case is, that i want to find and pass the ID session. Where the id number is found in the same row as the Username session, passed from the login.

The problem is, around 75% of the time i login, i get the error:
Quote:
No database selected


"No database selected" sounds like a SQL problem, but on the other hand since i can login the last 25% i also suspect that it might be the session?
Quote:

<?php
require_once("Connections/DaTaBaSeR.php");
$Violet = $_SESSION["User_Username"];
$Fuchsia = mysql_query("
SELECT users.ID
FROM users
WHERE users.Username = '$Violet'")
or die(mysql_error());
while($row = mysql_fetch_array($Fuchsia))
{
$_SESSION["ID"] = $row["ID"];
}
?>


The session "MM_Username" is sent from a prior page:

Quote:
$_SESSION['User_Username'] = "Vanilla";


Anyone, knows what it is that causes the problem?



And btw. i tested this on my own test server, and on frihost's one. So i don't think it's MySQL.
jylan
I'm just wondering if you have actually selected a database to work with HeavyVanilla, because that is all your error means. If you had multiple databases the script wouldn't know which one you wanted to access tables in, so try using something like the following code in your mysql connection script:

Code:
$dbname = 'DATABASENAME';
mysql_select_db($dbname);


Please correct if I'm wrong all you crack coders out there Smile.
HeavyVanilla
That was also what i thought at first, but since i got so far i doesn't think it's it. I mean, the prior login uses the same connection file:
Quote:
The DaTaBaSeR file:
<?php
$hostname_DaTaBaSeR = "localhost";
$database_DaTaBaSeR = "heavyvan_member";
$username_DaTaBaSeR = "heavyvan_member";
$password_DaTaBaSeR = "XXX";
$DaTaBaSeR = mysql_pconnect($hostname_DaTaBaSeR, $username_DaTaBaSeR, $password_DaTaBaSeR) or trigger_error(mysql_error(),E_USER_ERROR);
?>
kv
try mysql_connect instead of mysql_pconnect. Sometimes persistent connections pose few problems.

for more info http://jp2.php.net/mysql_pconnect
tepani2008
$hostname = "localhost";
$database = "xx";
$username= "root";
$password = "root";

mysql_connect($hostname,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "SELECT ID FROM users WHERE Username = '$Violet'";

$result = mysql_query($query);

if (mysql_num_rows($result) >= 1)
{
//your code here.......
}


hopefully that will help..
HeavyVanilla
Brilliant! Thanks Tepani! Very Happy

Well...you gotta' learn from your errors, so...Razz
What exactly was wrong?
rvec
you didn't select a database...
HeavyVanilla
I did select a database...
It was something here, that helped:

Quote:
$query = "SELECT ID FROM users WHERE Username = '$Violet'";

$result = mysql_query($query);

if (mysql_num_rows($result) >= 1)
{
//your code here.......
}

mathiaus
tepani2008 wrote:
$hostname = "localhost";
$database = "xx";
$username= "root";
$password = "root";

mysql_connect($hostname,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "SELECT ID FROM users WHERE Username = '$Violet'";

$result = mysql_query($query);

if (mysql_num_rows($result) >= 1)
{
//your code here.......
}


That big red line selects the database and is NOT present in any of the code that you posted!

You set the name of your database in a variable but didn't use it anywhere.

Your SELECT statement is from a table within a database.
albuferque
Yes, used die instead of trigger error.

$con= mysql_connect($host,$user,$password) or die ("Connection problems" . mysql_error());
$dbselect= mysql_select_db ($db,$con) or die ("Error selecting database" . mysql_error());
$results=mysql_query($query) or die ("Query error" . mysql_error());


Then you can proceed to process $results



Confused Confused Confused Confused Confused Confused Confused
HeavyVanilla
Well, anyway thanks all Wink
Related topics
How do we install Invision Board manually through cpanel?
MySQL statement error (got me going)
phpBB Error, seems to be a MYSQL DB error...
Suppressing mysql error
mysql base error please help
MySQL socket error
mysql syntax error I can't find why
session Error
MySQL/PHP Error..
phpMyAdmin - MySQL Ext error...
MySQL connection error on Server 2?
MYSQL Database Error on Server 2
Mysql ERROR
MySQL Error
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.