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:

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.

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.

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:

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.