I think this is Nested PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
markosjal
Forum Commoner
Posts: 63
Joined: Fri Apr 16, 2010 10:15 pm

I think this is Nested PHP?

Post by markosjal »

I know I have done this before however I seem to have a mental block and can not find where I may have done it so examples are appreciated.

I have a webform that should not show some components if a user is not logged in so I want to show those fields only when in admin or a user is logged in. I know this is not right and I am most certainly fouling up on the quotes and nested PHP.

Code: Select all

<td>
<?php if ($in_admin || $logged_in)
{echo '
<input name="showemail" type="radio" value="0"''<?php if(isset($data['showemail']) && $data['showemail']==EMAIL_HIDE) echo "checked"; 
?> '>'</td>;
else 
{
echo $somevariable;
} ?>
Any help appreciated
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: I think this is Nested PHP?

Post by Jade »

You can't have php tags inside of each other. You also have several syntax errors.

Code: Select all

<td>
<?php if ($in_admin || $logged_in)
{
  echo '<input name="showemail" type="radio" value="0"';
  if(isset($data['showemail']) && $data['showemail']=='EMAIL_HIDE') echo " checked";
  echo '>';
}
else
   echo $somevariable;
?>
</td>
Last edited by Jade on Thu Jul 29, 2010 2:25 pm, edited 1 time in total.
shawngoldw
Forum Contributor
Posts: 212
Joined: Mon Apr 05, 2010 3:38 pm

Re: I think this is Nested PHP?

Post by shawngoldw »

try

Code: Select all

<td>
<?php 
if ($in_admin || $logged_in)
{
    echo '<input name="showemail" type="radio" value="0"';
    if(isset($data['showemail']) && $data['showemail']==EMAIL_HIDE) echo " checked"; 
    echo ' />';
else 
{
echo $somevariable;
}
 ?>
</td>
You can't put a <?php tag in another <?php tag. that doesn't work

edit: looks like I got beat to the reply
markosjal
Forum Commoner
Posts: 63
Joined: Fri Apr 16, 2010 10:15 pm

Re: I think this is Nested PHP?

Post by markosjal »

I tried this,

Code: Select all

<table border="0" cellspacing="1" cellpadding="0">
				<tr>
					<td><?php
				if ($in_admin || $logged_in)
				{
    				echo '<input name="showemail" type="radio" value="0"';
    				if(isset($data['showemail']) && $data['showemail']==EMAIL_HIDE) echo " checked";
    				echo ' />';
?>
				</td>
					</tr>
				<tr>
					<td><input name="showemail" type="radio" value="2" <?php if(!isset($data['showemail']) || $data['showemail']==EMAIL_USEFORM) echo "checked"; ?>></td>
					<td><?php echo $lang['POST_EMAILOPTION_USEFORM']; ?></td>
					</tr>
				<tr>
					<td><input name="showemail" type="radio" value="1" <?php if($data['showemail']==EMAIL_SHOW) echo "checked"; ?>>&nbsp;</td>
					<td><?php echo $lang['POST_EMAILOPTION_SHOW']; ?></td>
					</tr>
					</table>


the original code was

Code: Select all

<table border="0" cellspacing="1" cellpadding="0">
				<tr>
					<td><input name="showemail" type="radio" value="0" <?php if(isset($data['showemail']) && $data['showemail']==EMAIL_HIDE) echo "checked"; ?>></td>
					<td><?php echo $lang['POST_EMAILOPTION_HIDE']; ?></td>
					</tr>
				<tr>
					<td><input name="showemail" type="radio" value="2" <?php if(!isset($data['showemail']) || $data['showemail']==EMAIL_USEFORM) echo "checked"; ?>></td>
					<td><?php echo $lang['POST_EMAILOPTION_USEFORM']; ?></td>
					</tr>
				<tr>
					<td><input name="showemail" type="radio" value="1" <?php if($data['showemail']==EMAIL_SHOW) echo "checked"; ?>>&nbsp;</td>
					<td><?php echo $lang['POST_EMAILOPTION_SHOW']; ?></td>
					</tr>
					</table>
And the page fails to load,
shawngoldw
Forum Contributor
Posts: 212
Joined: Mon Apr 05, 2010 3:38 pm

Re: I think this is Nested PHP?

Post by shawngoldw »

try

Code: Select all

<table border="0" cellspacing="1" cellpadding="0">
            <tr>
               <td><?php
            if ($in_admin || $logged_in)
            {
                echo '<input name="showemail" type="radio" value="0"';
                if(isset($data['showemail']) && $data['showemail']==EMAIL_HIDE) echo " checked";
                echo ' />';
            }
?>
            </td>
               </tr>
            <tr>
               <td><input name="showemail" type="radio" value="2" 
                      <?php if(!isset($data['showemail']) || $data['showemail']==EMAIL_USEFORM) echo "checked"; ?>></td>
               <td><?php echo $lang['POST_EMAILOPTION_USEFORM']; ?></td>
               </tr>
            <tr>
               <td><input name="showemail" type="radio" value="1" <?php if($data['showemail']==EMAIL_SHOW) echo "checked"; ?>>&nbsp;</td>
               <td><?php echo $lang['POST_EMAILOPTION_SHOW']; ?></td>
               </tr>
               </table>
you're missing a }
also turn on error reporting, it will tell you where you're error is
markosjal
Forum Commoner
Posts: 63
Joined: Fri Apr 16, 2010 10:15 pm

Re: I think this is Nested PHP?

Post by markosjal »

Thanks for the help on this howeever there were too many errors for my stupidity and the complexity of all of the code that needed to be edited. It was easier to make if and elseif with includes.
Post Reply