Page 1 of 1

Gah Another problem :S (Sessions maybe)

Posted: Sat Sep 03, 2005 9:31 am
by ericburnard
Hey again. I decided to start learning about sessions today seing as everywhere says you should learn them first. with trying to do this on my mbers page i came up with a problem of two databases open in one bit of php code.

the code if quite long but you only really nead the top bit i think. here it is

Code: Select all

<?php 
session_start(); 
header("Cache-control: private"); //IE 6 Fix 

include('http://eric.madashatters.com/header.inc');

if($_SESSION['logedin']){ 

$link = mysql_connect('localhost', '*******', '*************') 
   or die('Could not connect: ' . mysql_error()); 
mysql_select_db('madashat_mail') or die('Could not select database'); 

$username = mysql_real_escape_string($_GET['user']); 
$mail = $_GET['mail']; 
$query = "SELECT * FROM pm WHERE user='$username' AND new='New'"; 
$result = mysql_query($query) or die(mysql_error()); 
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
  $i++; 
} 
echo "<center>You have " . $i . " new messages<BR><BR>"; 

mysql_close($link)  // I think this is what the prblem is

// Connecting, selecting database 
mysql_connect('localhost', '*******', '*******')   // Even though it says its on this line
   or die('Could not connect: ' . mysql_error()); 
mysql_select_db('madashat_users') or die('Could not select database');  

$username = mysql_real_escape_string($_GET['user']); 
$query2="SELECT * FROM users WHERE username = '$username'";
$result2=mysql_query($query2);
$num=mysql_numrows($result2);

echo "<table cellpadding=10><tr><td align='left'><BR>
<div class='white'><center>
(the code continues)
I no this is prob really simple but im stuck :S lol

any help would be great
Thanks
Eric

Posted: Sat Sep 03, 2005 9:35 am
by anjanesh

Code: Select all

// Connecting, selecting database
mysql_connect('localhost', 'username', 'password')   // Even though it says its on this line
   or die('Could not connect: ' . mysql_error());
mysql_select_db('db1') or die('Could not select database');
whats the error generated by mysql_error() ?

Posted: Sat Sep 03, 2005 9:36 am
by feyd
you're guess is correct.. mysql_close() needs a semi-colon to finish the statement. ;)

Posted: Sat Sep 03, 2005 9:37 am
by Maugrim_The_Reaper
Test the value of

$_SESSION['logedin']

???


What is this supposed to be set to, and what is it actually set to. Try using var_dump to see what it holds, and ensure its a valid value. I assume it should be either a true/false boolean value?

Just make certain there is not the most obvious error - trying to evaluate a string of value "false" as false. Any string with content will return true when the sole condition of an if statement.

Posted: Sat Sep 03, 2005 9:37 am
by ericburnard

Code: Select all

Parse error: parse error, unexpected T_STRING in /home/madashat/public_html/eric/nm.php on line 26
i forgot to take out my username and password but have done it in my post noe. you were obviously very quick to respond and wissed the cange :p could you take it out of your post please.

Thank you :D

Eric

Posted: Sat Sep 03, 2005 9:45 am
by ericburnard
Thanks Feyd :D but now im getting the error

Code: Select all

Parse error: parse error, unexpected ':' in /home/madashat/public_html/eric/nm.php on line 74
which is part of the header (location: bit

Maugrim

The tutorial i am using shows this for the if function bit

Code: Select all

<?php 
// start the session 
session_start(); 
header("Cache-control: private"); //IE 6 Fix 
$_SESSION = array(); 
session_destroy(); 
echo "<strong>Step 5 - Destroy This Session </strong><br />"; 
if($_SESSION['name']){ 
    echo "The session is still active"; 
} else { 
    echo "Ok, the session is no longer active! <br />"; 
    echo "<a href=\"page1.php\"><< Go Back Step 1</a>"; 
} 
?>
It dosnt use any boolien so i just assumed that it ment "if the session is there then......."

:S am i wrong does it need to be

Code: Select all

if($_SESSION['name'] = TRUE;) {
??

Thanks again
Eric

Posted: Sat Sep 03, 2005 12:02 pm
by feyd
Could you post lines 64-84 ?

Posted: Sat Sep 03, 2005 12:11 pm
by ericburnard

Code: Select all

<tr>
<td><br><center><div class='white'>Welcome back";

echo $_SESSION['susername'];

echo "!!!<br><br>
This is your main members page which will be displayed everytime you login. Over on the right there is your main navigation menu for travling through the members area. <br><br>Also in the next few weeks i will get around to making a bar along the top (just underneath the main navigation bar) where you can see who is online and how many new email messages you have in your have in your inbox.<br><BR>Enjoy<br> Eric x x x <BR></td></tr></table></td></tr></table>";

} else {

header (location: http://eric.madashatters.com/login.html); // Line 74

}
?>


<BR><BR>
<?
include('http://eric.madashatters.com/footer.inc')
?>

Posted: Sat Sep 03, 2005 12:16 pm
by feyd
can you post the entire string involved in the first part that got truncated?

Posted: Sat Sep 03, 2005 12:40 pm
by ericburnard
I didnt quite understand what you were asking for so her is the whols script :s sorry

Code: Select all

<?php 
session_start(); 
header("Cache-control: private"); //IE 6 Fix 

include('http://eric.madashatters.com/header.inc');

if($_SESSION['logedin']){ 

// Connecting, selecting database 
$link = mysql_connect('localhost', 'madashat_eric', 'gateway2') 
   or die('Could not connect: ' . mysql_error()); 
mysql_select_db('madashat_mail') or die('Could not select database'); 

$username = mysql_real_escape_string($_GET['user']); 
$mail = $_GET['mail']; 
$query = "SELECT * FROM pm WHERE user='$username' AND new='New'"; 
$result = mysql_query($query) or die(mysql_error()); 
while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ 
  $i++; 
} 
echo "<center>You have " . $i . " new messages<BR><BR>"; 

mysql_close($result);

// Connecting, selecting database 
mysql_connect('localhost', 'madashat_eric', 'gateway2') 
   or die('Could not connect: ' . mysql_error()); 
mysql_select_db('madashat_users') or die('Could not select database');  

$username = mysql_real_escape_string($_GET['user']); 
$query2="SELECT * FROM users WHERE username = '$username'";
$result2=mysql_query($query2);
$num=mysql_numrows($result2);

echo "<table cellpadding=10><tr><td align='left'><BR>
<div class='white'><center>

<br><p align='left'>
<table style='border: dotted 1px'>
<tr>
<td width=270><center><u><div class='white'>Your Menu</u>
</td>
</tr>
<tr>
<td><br><center><a href='http://eric.madashatters.com/mail.php?user=$username'>Your Inbox</a>
<br>
<a href='http://www.madashatters.com/eric/mpupload.php?user=$username'>Upload Pictures</a>
<br>
<a href='http://www.madashatters.com/eric/menu.php?page=photos&gallery=$username'>View Your Gallery</a>
<br>
<a href='http://www.madashatters.com/eric/eblog.php?user=$username'>Edit Your Blog</a>
<br>
<a href='http://www.madashatters.com/eric/mblog2.php?user=$username'>View Your Blog</a>
<br>
<a href='http://www.madashatters.com/eric/profiles.php?user=$username'>Profiles</a>
<br><br>
</td></tr></table>
</td><td align='right'>
<p align='right'><table style='border: dotted 1px width=420'>
<tr>
<td><u><div class='white'></u>
</td>
</tr>
<tr>
<td><br><center><div class='white'>Welcome back";

echo $_SESSION['susername'];

echo "!!!<br><br>
This is your main members page which will be displayed everytime you login. Over on the right there is your main navigation menu for travling through the members area. <br><br>Also in the next few weeks i will get around to making a bar along the top (just underneath the main navigation bar) where you can see who is online and how many new email messages you have in your have in your inbox.<br><BR>Enjoy<br> Eric x x x <BR></td></tr></table></td></tr></table>";

} else {

header (location: http://eric.madashatters.com/login.html);

}
?>


<BR><BR>
<?
include('http://eric.madashatters.com/footer.inc')
?>

Sorry :S
Eric

Posted: Sat Sep 03, 2005 12:42 pm
by feyd

Code: Select all

header ('Location: http://eric.madashatters.com/login.html');