Jump to content

Session help


mydownfall00

Recommended Posts

I can't seem to get the session array to work. I am using a if count to make sure the password matches on the username and password. 

 

This is my login script. This page executes after typing in your username and password.

$db_name="wcdmembers"; 
$tbl_name="members"; 
 
mysql_connect("$host", "$username", "$password");
mysql_select_db("$db_name");

$wcdname=mysql_real_escape_string($_POST['wcdname']);
$pword=mysql_real_escape_string($_POST['pword']);
 
$sql="SELECT * FROM $tbl_name WHERE wcdname='$wcdname' and pword='$pword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
$_SESSION['wcdname'] = 'wcdname';
$_SESSION['pword'] = 'pword';

} else {
  echo "Wrong Username or Password. <a href=index.html>Try Again</a>";
}

$sql="SELECT * FROM $tbl_name";
$result1=mysql_query($sql);

while ($row = mysql_fetch_array($result)) 
{ 
$fname= $row["fname"]; 

echo "Welcome <a href=myaccount.php style=color:#000000 onMouseover=showmenu(event,linkset[6]) onMouseout=delayhidemenu()>$wcdname!</a>";

}

?>
<?php 
session_start();
$_SESSION["wcdname"] = $wcdvalue;
?>
        
<?php
echo "Today is ";
echo date('l \t\h\e jS \o\f F Y') ;
?>

In the code above you also see a select * from before it displays the Welcome $wcdname. I had to use the select * because I wanted to show the first name and not the username. Now im not sure on how or what to do because I want to use the username on the comments table because people can have the same first name. Unless I want to go by ID? I do have an ID auto inc set on each user in wcdmembers.  ----- EDIT

 

I created the session array after the welcome display. I attempted to put it all in the same php block but it would give me an error. Right now it will display the wcdname(username) but now the date wont appear with the 2nd php block session.

 

I am attempting to have the user leave a comment and carrying over information to the next page. This way when they leave a comment it will recognize the username and store it in a new table. This is my current comment.php page code. Its not much because I cant get the session to start.

  <?php
session_start()

$wcdvalue = $_SESSION['wcdname'];                  (line 156)

echo "Welcome $wcdname";
?>

This is where I get the error : Parse error: syntax error, unexpected T_VARIABLE in /home/content/80/11355280/html/comment.php on line 156

Link to comment
https://forums.phpfreaks.com/topic/280599-session-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.