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>

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?

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'])

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.