The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Embedding variables

Hi all

I have managed to pull some items from a database and create links on that page. The user can select a product link then when they click on a link they are show the product on the next page. On that page I have an email form. I would like to embed the product name into the message of the email or have it as a hidden field but still embedded into the message body of the email so it displays in the message when the recipent sees it. How can I put the below variable which displays the product name into the message body along with any message the user rights into the textarea?

$row['ProductName']

The only parameters you can have are

mail (to, subject, body, headers)

$message = $_REQUEST['message'] ;

the above requests the message the user writes in the text area but I am not sure how to embed $row['ProductName'] into this?

Hope this makes sense. Still a novice to php so any help would be great thanks

Sorry I have another query, below is some asp its an if statement and it says it redirects the user to the previous page if they click the cancel button. How would I do the same in php? I seem to have problems with php page redirects.

if(Request.Form("Cancel")<>"") then
response.Redirect("send.asp")
end if

sorry probably going to sound dumb does that not re-direct the user to another page the minute they load that page? How do I link that in with the form so if they hit the button 'cancel' it takes them to that re-direct page?

After your header redirect. Otherwise it will continue parsing the rest of the file, which could be bad depending what else is there. Of course make sure you wrap that if block in braces before doing that.

The URL you put in the Location header should be a full, absolute URL. Browsers aren't guaranteed to support relative URLs, as you have now.

I assume you set some session variable like $_SESSION['loggedIn'] = true; when you login first and then check this on pages to see if user is logged in or something familiar. So you could do something like this:

HTML

Code:

<a href="mypage.php?logout">Logout</a>

PHP Code:

if (isset($_GET['logout'])){$_SESSION['loggedIn'] = false; // or just unset the variable // unset($_SESSION['loggedIn']);}

Just to clarify do I need to put the above together on every page? And where you have mypage.php should that be login.php which is my login page?

Many thanks

Rob

mypage.php is the page that link is located to. And optimal would be that you have so called "front controller" that takes care of the executions and includes the stuff on every page. But you could also add the link on every page you want to display the logout link.