Jump to content

using a _GET variable in a variable output text string


c_martini

Recommended Posts

First, forgive my lack of php knowledge, but I am a designer who has been tasked with some minor php work...

 

* I have a php page with an iframe including a php form.

* I have set a variable in the url of the iframe src attribute like so: <iframe src="mailForm.php?pageSubject=Fundraising"></iframe>

* I need to output this variable within a declared variable value in the mailForm.php file:

 

$subject = "Enquiry about $pageSubject"

 

* I am able to echo the variable in the php page like this:

 

<?php echo $_GET['pageSubject']; ?>

 

How can I output that variable within the text string of $subject?

 

:confused:

Link to comment
Share on other sites

Try this:

$subject = "Enquiry about {$pageSubject}";

echo $subject;

 

Although it should print it without the curly braces? It's only single quotes which print the variable name rather than the value.

 

Regards,

 

L2c.

Edited by Love2c0de
Link to comment
Share on other sites

Oh sorry. Try this:

$subject = "Enquiry number: {$_GET['pageSubject']}";

echo $subject;

 

You may want to check and see if it is set first by doing this:

if(isset($_GET['pageSubject']))
{
  $subject = "Enquiry number: {$_GET['pageSubject']}";

  echo $subject;
}
else
{
//do something here.
}

Does this help?

 

Regards,

 

L2c.

Link to comment
Share on other sites

Oh sorry. Try this:

$subject = "Enquiry number: {$_GET['pageSubject']}";

echo $subject;

 

You may want to check and see if it is set first by doing this:

if(isset($_GET['pageSubject']))
{
 $subject = "Enquiry number: {$_GET['pageSubject']}";

 echo $subject;
}
else
{
//do something here.
}

Does this help?

 

Regards,

 

L2c.

 

Thanks! :happy-04:

Link to comment
Share on other sites

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.