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!
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
<?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
// 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() ?
Last edited by anjanesh on Sat Sep 03, 2005 9:42 am, edited 1 time in total.
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.
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.
<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')
?>
<?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