0

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>
3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by capton
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?

0

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

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

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.