954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

$_SESSION not wrking

Please i want to set sessions in my php file which includes
a form but the session doesn't work.This is my code sample.
I need help please!

<?php
$conn=mysql_connect("localhost","root","");

mysql_select_db("my_db");

session_start();

if(isset($_SESSION['count']))
 $_SESSION['count']=$_SESSION['count']+1;

 else
$_SESSION['count']=1; 

if(!($_SESSION['count']=$_POST['reg']))
die("SESSION NOT SET SUCCESSFULLY!");

else
echo "SESSION SUCCESSFUL!";
?>

<html><head></head><body>

 <form method="POST" action="<?php echo $PHP_SELF ?>">
 <input type = "hidden" name = "reg" value = "<?php echo $_SESSION['count'];?>" />
 <!--     FORM INPUT -->

 </body></html>
capton
Newbie Poster
23 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

Is session_start() at the top of every file? particularly the one that is before this one?

It would be clearer to notice why things aren't working if you could show us the other files?

BenzZz
Junior Poster
116 posts since Feb 2011
Reputation Points: 10
Solved Threads: 6
 

What are you trying to do in this comparison ?

if(!($_SESSION['count']=$_POST['reg']))


You might want to change that to

if($_SESSION['count']!=$_POST['reg'])
as.bhanuprakash
Junior Poster
109 posts since Dec 2009
Reputation Points: 16
Solved Threads: 21
 

Any time i refresh the page, it automatically submit the details on the form
to the database and wants to create a session so that it stops but the session
doesn't work

capton
Newbie Poster
23 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

Any time i refresh the page, it automatically submit the details on the form
to the database and wants to create a session so that it stops but the session
doesn't work

capton
Newbie Poster
23 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

ok. jx found the solution.
made a mistake in my code.
THANKS

capton
Newbie Poster
23 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You