Page 1 of 1

session help

Posted: Wed Aug 25, 2004 11:54 pm
by Think Pink
hello,
i have the follwing script. I thimk for you is prety obvious what it does and I don't have to explain, but if you want me to, pls tell me and I will.
Ok, what i want to do is after I insert data into the country filed and submit the form, if I want to refresh the page not to be able to. I want to receive a warning message that the page has expired. The same thing if I hit the back button of the browser. Now, I know hat this has to be done with sessions, but i don't know to well how it should be done. Pls don't write the script for me, but I would appreciate if you would advice me.
Thx

Code: Select all

$message = "";
if(isset($_POST['addCountry']))	
{
$my_form_url = "http://localhost/index.php";
$my_form_url = strtolower($my_form_url);
$incoming_url = strtolower($_SERVER['HTTP_REFERER']);
								
if ($my_form_url == $incoming_url) 
{
if ($_POST['country'] == "") 
{
$message = "<span class='mesaj3'><li>You must fill all fields!</span>";
}
else
{
$sql = "SELECT *  FROM tableCountry WHERE country_name='".$_POST['country']."'";
$resursa = mysql_query($sql);
if (mysql_num_rows($resursa) != 0) 
{
$message = "<span class='mesaj3'><li>Error !</span>";
} else {
$sql = "INSERT INTO tableCountry(country_name) VALUES('".$_POST['country']."')";
mysql_query($sql);
$message = "<span class='mesaj4'><li>OK !</span>";
} // end else
}	// end else					
} else {} // end else
} // end if

Posted: Thu Aug 26, 2004 12:26 am
by John Cartwright
ok... we'll this is the most i can do unless you want me to write it for you, because its taht straight forward...


after the insert

1. get a session variable
2. at the top of the page check to see if the session variable exists, if not, then do the rest of the code.

[php_man]sessions[/php_man]

session help

Posted: Thu Aug 26, 2004 2:23 am
by Think Pink
ok, here is what I did:

i declared sesion_start();
at the top of the page
then the variable I made it like this $_SESSION['country'] == $_POST['country'];

well, still not working. perhaps you will have to give me more infos. I read some articles about sessions but now I'm even more confused.

Posted: Thu Aug 26, 2004 9:26 am
by feyd
were you trying to set the session variable? then you want something like:

Code: Select all

$_SESSION['country'] = $_POST['country'];