code says im not logged in

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
bfsog
Forum Newbie
Posts: 8
Joined: Thu Feb 10, 2005 6:14 am
Location: UK

code says im not logged in

Post by bfsog »

The following code is where I add blog entries into a database. I have been working on this for about a week now.

What happens is, I always get the "You have to sign in first", however, I am signed in when I try to add.

Code: Select all

<html>

<head>

<?php include ("constants.inc"); ?>

<?php echo"<title>$SiteTitle</title>"?>

<?php echo"<link rel="stylesheet" href="$cssfile" type="text/css">"?>

</head>

<body>
<?php
include ("connect.php");

if ( !$username  || !$title || !$comment ) &#123;

echo "Please make sure all fields are filled in";

				&#125;
else &#123;

if (isset($_SESSION&#1111;'name'])) // 20
&#123;

else 					&#123;
$date = date("d/m/Y"); 
$name = preg_replace("/>/",">",$name); 
$name = preg_replace("/</","<",$name);
$comment = preg_replace("/>/",">",$comment); 
$comment = preg_replace("/</","<",$comment);
$comment = ereg_replace("<","",$comment);
$comment = ereg_replace(">","",$comment);
$wrap = intval(45)+1;
$comment = wordwrap($comment, $wrap, ' ', 1);
$comment = stripslashes($comment);

$yname = stripslashes($name);
$ytitle = stripslashes($title);
$ycomm = stripslashes($comment);


	$insert = "INSERT INTO content (username,title,date,comment)
	VALUES ('$yname','$ytitle','$date','$ycomm')";
	mysql_query($insert) or die ("Could not add data to the table");
	$query = "SELECT * FROM content";
	$result = mysql_query($query);
	$numrows = mysql_num_rows($result);

	echo "Thankyou, your post has been added<br><br>";

					&#125;
&#125;
else						&#123;
echo 'You have to sign in first ';
echo '<a href="login.php" title="Login">Login</a>';
						&#125;
&#125;
?>
As I say, if I am logged in, and the basic validation works, I should get the message "Thankyou, your post has been added"

If anyone solves this for me I would be very grateful.

Thanks
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

1) i am not really sure why you have an else statement here...

Code: Select all

if (isset($_SESSION&#1111;'name'])) // 20 
&#123; 

else                &#123; 
$date = date("d/m/Y");

2) have you called session_start() somewhere?
Post Reply