one who can solve this php code ^ echo "<option><?php echo htmlspecialchars( $Player[ 'Name' ] ); ?></option>"; ^ And the error on the page http://gyazo.com/aaf5d029a1da9d52ea3341dd01e55960

Recommended Answers

All 25 Replies

First Point:
Well what the hell am I meant to solve if I don't even know what the error message is?
echo "<option><?php echo htmlspecialchars( $Player[ 'Name' ] ); ?></option>"; isn't good enough my friend.

Second Point:
Can you provide some source code of report.php and give us a bit of a hand here?

Put some effort in.

Just a quick notice on formatting... Does PHP allow $Player[ 'Name' ]? Shouldn't it be $Player['Name'] (notice the white spaces)?

Also, I am not sure there is Is_Array() but there is is_array()... The language is case-sensitive!

I also tried with:
echo "<option>";
echo htmlspecialchars( $Player[ 'Name' ] );
echo "</option>";

Heres something based on what we've said so far:

if(is_Array($Players)){
    foreach($Players as $Player) {
        $option = htmlspecialchars($Player['Name']);
        echo "<option>". $option."</option>";
    }
}

Neaten your code up and make it consistant.

The above should solve your problem, if not, check that $Players array contains the correct variables.

Member Avatar for diafol

@mathiaslisborg.jakobsen

In future, could posters please paste error messages and any relevant code into the editor so that they appear in the thread. Nothing more annoying than having to follow links. Some contributors may be using a smartphone - any idea how tedious opening image dumps or code repos can be?

@Taywin
I believe that whitespace around the quoted itemname inside the square bracket is allowed.

$l = array('m'=>'fine');
echo $l[ 'm' ];

Works fine for me. Also Is_Array() is allowed - variables are case sensitive, but I believe functions are case insensitive.

$l = array('m'=>'fine');
echo Is_Array($l); //displays 1

Verify that your $Player variable contains what you are looking for (using echo to inspect). Also, your original script in your report.txt file contains nested <option> and </option>. Watch out for that.

Member Avatar for diafol
<?php if( Is_Array( $Players ) ): ?>
<?php foreach( $Players as $Player ): ?><option>";
echo "<option><?php echo htmlspecialchars( $Player[ 'Name' ] ); ?></option>";
echo "</option><?php endforeach; ?>
<?php else: ?>
                            <option>No players in da house</option>
<?php endif; ?>

The area concerned with your error seems to be the above. remember that error lines do not necessarily relate to the line number itself, it may be a consequence of an upstream error.

<?php foreach( $Players as $Player ): ?><option>";

Seems a bit odd. Also

echo "</option><?php endforeach; ?>

That doesn't make sense.

You have used alternative syntax for control structures, which in itself is fine, but in so doing you seem to have mashed up the html and the php. I fail to see why you are using <?php..?> tags or echo on nearly every line. This is slooow. Try to separate your html and php as much as possible.
Build up your strings using concatenation and echo just once if possible.

Member Avatar for diafol

Please... pretty please... "mod speaking" - paste your code and errors directly into this thread.

Member Avatar for diafol
echo "<option><?php echo htmlspecialchars( $Player[ 'Name' ] ); ?></option>";

Again, sigh, why are you placing php tags inside an echo command?

echo "<option>" . htmlspecialchars($Player['Name']) . "</option>";

should work.

I just started with low echo so is not so into it
-if there are errors in the message it is because I translate on google :)

Member Avatar for diafol

Irrelevant. Get a good tutorial on the basics of php and how to use it with html. Your way of mixing them up is not very good. Code should be clean.

post the actual error message, not a link.
follow the instructions you have been given

Please... pretty please... "mod speaking" - paste your code and errors directly into this thread.

'mod' is the bloke who kicks your ass off the site when you annoy them enough

Member Avatar for diafol

I think I've made it pretty clear now, please POST the code, do not provide links. This is getting frustrating.

<?php
include 'header.php';
?>
<?php
    require ('steamauth/steamauth.php');  

?>      
<?php
if(is_Array($Players)){
    foreach($Players as $Player) {
        $option = htmlspecialchars($Player['Name']);
    }
}
?>
<?php
if(!isset($_SESSION['steamid'])) {

    echo "<center>Welcome guest! please login to making a report and view your reports \n \n";
    echo steamlogin();
    echo "</center>";

}  else {
    include ('steamauth/userInfo.php');

    //Protected content
echo "<div class='row show-grid'>
<div class=col-md-6><div class='thumbnail'>
<div class='media'>
<a class='pull-left' href='#'>
<img src='".$steamprofile['avatarmedium']."' style='width: 64px; height: 64px;'>
</a>
<div class='media-body'>
<h4 class='media-heading'><a href='".$steamprofile['profileurl']."'>".$steamprofile['personaname']."</a></h4>
ID: ".$steamprofile['steamid']."
<div class='pull-right'>";
     echo logoutbutton();
     echo " </a>
</div></div></div></div>";
    echo "<select class='form-control'>          
<option>". $option."</option>";
echo "<?php endforeach; ?>
<?php else: ?>
                            <option>No players in da house</option>
<?php endif; ?>
</select>";
     echo "
     </select>
</div>   
<div class='col-md-6'>
<div class='list-group'>
<a href='#' class='list-group-item active'>
<center><h4 class='list-group-item-heading'>Your reports</h4></center>
</a>
<a href='#' class='list-group-item'>
<h4 class='list-group-item-heading'>List group item heading</h4>
<p class='list-group-item-text'>....</p>
</a>
<a href='#' class='list-group-item'>
<h4 class='list-group-item-heading'>List group item heading</h4>
<p class='list-group-item-text'>....</p>
</a>
</div> 
</div>
</div>";

}    
?>
<br>
<?php        
include_once('footer.php');
?>
          </div>
        </div>
    </div> 
</body></html>

And it only shows one player now, it will display all and have tested it with just php.

This code I'm 100% sure works.

    <select class="form-control">            
<?php if( Is_Array( $Players ) ): ?>
<?php foreach( $Players as $Player ): ?>
                            <option><?php echo htmlspecialchars( $Player[ 'Name' ] ); ?></option>
<?php endforeach; ?>
<?php else: ?>
                            <option>No players in da house</option>
<?php endif; ?>
</select>

This is the code I try and get to work with echo.

<?php if( Is_Array( $Players ) ) { echo '<select class="form-control">'; 
 foreach( $Players as $Player ) {
  echo "<option> htmlspecialchars( $Player[ 'Name' ] </option>";
  echo '</select'>;
 }
else {echo '<input class="form-control" type="text" disabled="disabled" Value="No players in da house">';
}

every timne you go to php, drop back to html, it adds processing time
If you can do it once
do it once

All thanks for the help :)

</option>"; in line 3
should be
</option>";}

Member Avatar for diafol
foreach( $Players as $Player ) {
  echo "<option> htmlspecialchars( $Player[ 'Name' ] </option>";
  echo '</select'>;
 }

The </select> should be outside the loop otherwise you'll get multiple close select tags.

commented: the post immediately above, :sad face: +13

I changed your last "long" listen to this.
My php is rusty but I think it will do the trick. I did not test it.. :s

<?php
include 'header.php';
require ('steamauth/steamauth.php'); 
//
// use "htmlspecialchars()" on each value of Players
if(is_Array($Players)){
    foreach($Players as $Player) {
        $Player = htmlspecialchars($Player);
    }
    unset($Player); // break the reference with the last element
}
//
if(!isset($_SESSION['steamid'])) {
    echo "<center>Welcome guest! please login to making a report and view your reports \n \n";
    echo steamlogin();
    echo "</center>";
}else{
    include ('steamauth/userInfo.php');
    //Protected content
    echo "
        <div class='row show-grid'>
        <div class=col-md-6><div class='thumbnail'>
        <div class='media'>
        <a class='pull-left' href='#'>
        <img src='".$steamprofile['avatarmedium']."' style='width: 64px; height: 64px;'>
        </a>
        <div class='media-body'>
        <h4 class='media-heading'><a href='".$steamprofile['profileurl']."'>".$steamprofile['personaname']."</a></h4>
        ID: ".$steamprofile['steamid']."
        <div class='pull-right'>
    ";
    echo logoutbutton();
    echo "
        </a></div></div></div></div>
        <select class='form-control'>
        ";
    if(empty($Players)){
        echo "<option>No players in da house</option>";
    }else{
        foreach($Players as $option){
            echo "
                <option>". $option ."</option>
            ";
        }
    }
    echo "
        </select> 
        </div>
        <div class='col-md-6'>
        <div class='list-group'>
        <a href='#' class='list-group-item active'>
        <center><h4 class='list-group-item-heading'>Your reports</h4></center>
        </a>
        <a href='#' class='list-group-item'>
        <h4 class='list-group-item-heading'>List group item heading</h4>
        <p class='list-group-item-text'>....</p>
        </a>
        <a href='#' class='list-group-item'>
        <h4 class='list-group-item-heading'>List group item heading</h4>
        <p class='list-group-item-text'>....</p>
        </a></div></div></div><br>
    ";
include_once('footer.php');
echo "
    </div></div></div></body></html>
    ";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.