session help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

session help

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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]
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

session help

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

were you trying to set the session variable? then you want something like:

Code: Select all

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