RyanSF07 Posted May 9, 2009 Share Posted May 9, 2009 Hi All, I trying to build a links database where users can add / edit their links. If the user has only one link -- no problem. He/She can go to their account page, click edit, and edit away. But if two or more, and they return to their account page to edit a second link, the Session[link_id] from the first link they chose carries over. And edits to that second link actually show up in the first record. I'm using iframes so I can't pass these in the url. How do I "update" the Session[link_id] variable so that the correct link id is passed when returning to the "account' page to edit several links? I've tried unset and http_session_var with no success. What I'd like to do is clear the session[link_id] variable completely once they open or come back to their account page, but then set that variable again when they click on the link they'd like to next edit. Below is the code: I've gutted it for simplicity. Thank you so much for your help! <?php session_start(); session_unset($_SESSION['link_id']); include_once ("contentdb.php"); if ($_SESSION[user_id]) { include_once ("nav_my_account.inc"); $content .= " <h1>$_SESSION[name]'s Account</h1> <h2>My links:</h2>"; $data = mysql_query("SELECT links.id, links.link_website_title, links.link_website_url, links.link_website_description, links.photo, first_name, last_name, DATE_FORMAT(date, '%M %D, %Y') as date FROM links, registered_users WHERE links.user_id = registered_users.id AND links.user_id = '" . $_SESSION['user_id'] . "' ORDER BY link_website_title ASC") or die(mysql_error()); (deleted this part for simplicity) $content3 .= " <p><b>".$info['link_website_title'] . " </b> " . "<a href = \"my_account_edit_this_link_2.php?link_id=$info[id]\">[Edit]</a>" $_SESSION['link_id']="$info[id]"; } Quote Link to comment https://forums.phpfreaks.com/topic/157454-solved-unset-a-variable-then-set-its-replacement-on-the-same-page-help/ Share on other sites More sharing options...
RussellReal Posted May 9, 2009 Share Posted May 9, 2009 ok.. heres how I would do it.. <?php // edit_link.php?id=link_id session_start(); if ($_SESSION['user_id']) { //assuming this is your simple way of checking if the user is logged in if ($id = (int) $_GET['id']) { // checks if GET 'id' is a number include('contentdb.php'); $res = mysql_query("SELECT * FROM links WHERE links.user_id = '{$_SESSION['user_id']}' AND links.id = '{$id}'"); if ($row = mysql_fetch_assoc($res)) { // do whatever you'd do to allow the user to edit it using $row for the data from the query } } } ?> and inside the file you're showing us.. just display the 'edit links' with the html resembling something like: <a href="edit_link.php?id=link_id">EDIT</a> and when they click that, redirect the iframe with like target="iframe_name" in the a tag.. and then you don't rly need to attach the link id in the sessions, access them with each request thru GET Quote Link to comment https://forums.phpfreaks.com/topic/157454-solved-unset-a-variable-then-set-its-replacement-on-the-same-page-help/#findComment-830129 Share on other sites More sharing options...
RyanSF07 Posted May 9, 2009 Author Share Posted May 9, 2009 Thank you, Russell. I tried that and ran into some problems. I went down the long windy path of retracing my steps and came full circle to original reason why I went with session variables to begin with -- and that is, I can't figure out how to pass a parent frame url $_Get to an iframe src url. Anyone know how to do that? Quote Link to comment https://forums.phpfreaks.com/topic/157454-solved-unset-a-variable-then-set-its-replacement-on-the-same-page-help/#findComment-830395 Share on other sites More sharing options...
.josh Posted May 9, 2009 Share Posted May 9, 2009 the same way you loaded the iframe up in the first place. Only add the var to it echo "<iframe src='blah.php?variable=" . $variable ."'></iframe>"; Quote Link to comment https://forums.phpfreaks.com/topic/157454-solved-unset-a-variable-then-set-its-replacement-on-the-same-page-help/#findComment-830408 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.