Jump to content

[SOLVED] unset a variable -- then set it's replacement on the same page: help


Recommended Posts

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]"; 
}

 

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

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?

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.