How to echo php code
Moderator: General Moderators
How to echo php code
I am trying to setup a survey form, and I want the survey to appear when the user first arrives (!$_POST['variable']), and then when they have complete the survey, I want the same page to display a thank you screen and submit the information to my database. The problem I am having is on the initial form because it also has a error check system (if ($_POST['variable'] {echo "Please select an option";}). My question is what is the syntax for placing php code in an echo command? echo "<?php some_code ?>"; only throws errors. Thanks for your help.
Code: Select all
<?php
echo htmlentities( '<?php echo \'Hello World\';?>' );
?>Code: Select all
echo some_expression;hawleyjr | Please use
I am wanting to have php code generated and executed. If this is possible, please let me know what I need to do. Thanks.
hawleyjr | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I'm sorry I didn't word that correctly. Let me write an example of what I am hoping to accomplishCode: Select all
<?
if (!$_POST['var'])
{
$msg = "$query = "SELECT row FROM tbl"
or die("Invalid query.");
$res = mssql_query($query)
or die("No results returned.");
while($line = mssql_fetch_row($res))
{
foreach ($line as $value)
{
echo "<input type=\"radio\" name=\"tutor\" value=\"$value\" />";
echo " $value ";
}
}";
}
else
{
$msg = "Thank you for completing the survey";
}
echo $msg;
?>hawleyjr | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]While I can't figure out what you're trying to do, and whatever you're doing I am fairly certain you're trying to do it the Wrong Way™, the function you need to look at is .
Code: Select all
eval();- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
use single quotes.
Code: Select all
echo '<?php echo "this is a test"; ?>';- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Code: Select all
<?php
$msg = '';
if (!$_POST['var'])
{
$query = "SELECT row FROM tbl" or die("Invalid query");
$res = mssql_query($query) or die("No results returned.");
while($line = mssql_fetch_row($res))
{
$msg .= '<input type="radio" name="tutor" value="' . $line['row'] . '" />';
$msg .= "\n";
$msg .= $line['row'] . " \n";
}
}
else
{
$msg = "Thank you for completing the survey";
}
echo $msg;
?>- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA