ballhogjoni Posted August 12, 2007 Share Posted August 12, 2007 How can I destroy the value of a variable? I tried unset() but all I have to do is refresh the page using the refresh button and the variables are still set. Quote Link to comment https://forums.phpfreaks.com/topic/64481-destroy-the-value-of-a-variable/ Share on other sites More sharing options...
HaLo2FrEeEk Posted August 12, 2007 Share Posted August 12, 2007 php is a line-by-line serverside language, unlike Javascript which runs on the client machine and so has the ability to update on-the-fly. You'd need to use post or get variables to modify the code when the page loads. Quote Link to comment https://forums.phpfreaks.com/topic/64481-destroy-the-value-of-a-variable/#findComment-321447 Share on other sites More sharing options...
ballhogjoni Posted August 12, 2007 Author Share Posted August 12, 2007 If i am not mistaken I do. my code session_start(); include('db.php'); include('functions.php'); checkLogin('1 2'); $query = mysql_query("SELECT * FROM users WHERE ID = '{$_SESSION['user_id']}'"); $row = mysql_fetch_array($query) or die(mysql_error()); $Username = $row['Username']; if (!empty($_POST['title'])) { $title = $_POST['title']; } if (!empty($_POST['desc'])) { $desc = $_POST['desc']; } if (!empty($_POST['price'])) { $price = $_POST['price']; } if (isset($title)) { $title_checked = strip_tags($title); } if (isset($desc)) { $desc_checked = strip_tags($desc); } if (isset($title_checked) && isset($desc_checked) && isset($price)) { if (!empty($title_checked) && !empty($desc_checked) && !empty($price)) { if (strlen($title_checked) > 20 || strlen($desc_checked) > 30) { $leng = '<span class="problemMessage">Please check the length of your Title and Description. Title is 20 Characters Max and Description is 30 Characters Max.</span>'; } elseif (strlen($title_checked) <= 20 && strlen($desc_checked) <= 30) { mysql_query("INSERT INTO products (Username, title, description, price) VALUES ('$Username','$title_checked','$desc_checked','$price')") or die(mysql_error()); $verbage = '<span class="goodMessage">Your product has been saved.</span>'; unset($title,$desc,$price); } } else { $verbage = '<span class="problemMessage">Product has NOT been Saved. Please enable Javascript & be sure to fill in all fields</span>'; unset($title,$desc,$price); } unset($title,$desc,$price); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/64481-destroy-the-value-of-a-variable/#findComment-321451 Share on other sites More sharing options...
aim25 Posted August 12, 2007 Share Posted August 12, 2007 put unset out of the if. Quote Link to comment https://forums.phpfreaks.com/topic/64481-destroy-the-value-of-a-variable/#findComment-321455 Share on other sites More sharing options...
ballhogjoni Posted August 13, 2007 Author Share Posted August 13, 2007 No I have tried that. It doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/64481-destroy-the-value-of-a-variable/#findComment-322043 Share on other sites More sharing options...
btherl Posted August 13, 2007 Share Posted August 13, 2007 Please explain in more detail what "It doesn't work" means. As halofreek said, unset() does NOT work across refreshes (the exception being session variables). If you explain what you want to do, then we can suggest an alternative. Quote Link to comment https://forums.phpfreaks.com/topic/64481-destroy-the-value-of-a-variable/#findComment-322067 Share on other sites More sharing options...
ballhogjoni Posted August 13, 2007 Author Share Posted August 13, 2007 AW...Thats what I am trying to fix. I am trying to make sure the 'product' is not saved again in the db if someone refreshes the screen. I have written my code to check the db for the 'product' and if it exists it will not add it. Quote Link to comment https://forums.phpfreaks.com/topic/64481-destroy-the-value-of-a-variable/#findComment-322084 Share on other sites More sharing options...
btherl Posted August 13, 2007 Share Posted August 13, 2007 Sounds great! Checking the db is the best solution. Quote Link to comment https://forums.phpfreaks.com/topic/64481-destroy-the-value-of-a-variable/#findComment-322087 Share on other sites More sharing options...
ballhogjoni Posted August 13, 2007 Author Share Posted August 13, 2007 Just seeing if there is another solution, as far as unset() Quote Link to comment https://forums.phpfreaks.com/topic/64481-destroy-the-value-of-a-variable/#findComment-322092 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.