-3

Im trying to echo whole modal with data from db. I want to use my other functions "getLocations and getdescriptions" in my new function. But... Html shows those functions as comments "<!--?php echo getLocations(); ?--> & <!--?php echo getdescriptions(); ?-->". How I can make these echos to work.

Code is not complete, so there is possible many problems, but this echo is my problem right now.

$output .= "
<tr data-toggle='modal' data-target='#startWorkTime".$location_row['name'].gmdate("j", $start_day)."' href=''>
    <td class='column7'>".gmdate("j", $start_day).".".gmdate("n", $start_day).".".gmdate("Y", $start_day)."</td>
    <td class='column7'>".$location_row['name']."</td>
    <td class='column7'><a href='https://www.w3schools.com/'>".$row['msg']."</a></td>
    <td class='column7'>".gmdate("G", $sum)."h ".gmdate("i", $sum)."m</td>
</tr>

<div class='modal text-center fade' id='startWorkTime".$location_row['name'].gmdate("j", $start_day)."' > 
    
    <div class='modal-dialog modal-dialog-centered' style='min-width:50%' >   
        
        <div class='modal-content' style='background-color: #fff; border-radius: 10px; border: none; padding: 0; box-shadow: 0 0.46875rem 2.1875rem rgba(90,97,105,0.1), 0 0.9375rem 1.40625rem rgba(90,97,105,0.1), 0 0.25rem 0.53125rem rgba(90,97,105,0.12), 0 0.125rem 0.1875rem rgba; color: #fff;  background-color: rgb(255, 255, 255);'>
            
            <div class='modal-body'>
                <button type='button' class='close text-danger' data-dismiss='modal'>&times;</button>  
                
                <div class=' text-dark'> 
                    <form class='form-card' action='work_time.php' method='post'>     
                        <div class='row justify-content-between text-left'>
                            <div class='form-group col-sm-12 flex-column d-flex'>                        
                                <h6>".$row['start']." ASD ".$row['stop']."Merkinnän id: ".$row['id']."</h6>
                            </div><div class='form-group col-sm-12 flex-column d-flex'>                    
                            <label class='form-control-label px-3'><b>Tiedot</b> <i>Muokkaa klikkaamalla</i></label> 
                            <div style='margin-left: 5px;margin-right: 5px;'>                       
                                <br>                  
                                <div class='form-group col-sm-10 flex-column d-flex' >                        
                                    <label class='form-control-label px-3 '> <b><i class='fa-regular fa-clock text-dark'></i> Aloitus</b></label>
                                    <input style='padding-left: 20px;padding-right: 20px;' type='datetime-local'    name='startdatetime'    value='".date('Y-m-d', strtotime($row['start_date']))."T".date('H:i', strtotime($row['start']))."'         >
                                </div>    
                                
                                <div class='form-group col-sm-10 flex-column d-flex' >                        
                                    <label class='form-control-label px-3 '> <b><i class='fa-regular fa-clock text-dark'></i> Lopetus</b></label>
                                    <input style='padding-left: 20px;padding-right: 20px;' type='datetime-local'    name='stopdatetime' value='".date('Y-m-d', strtotime($row['stop_date']))."T".date('H:i', strtotime($row['stop']))."'>        
                                    <br>
                                    <h6>Tunnit yhteensä: <b>".gmdate("G", $sum)."h ".gmdate("i", $sum)."m</b></h6>
                                </div>
                                
                                <div class='form-group col-sm-10 flex-column d-flex'> 
                                    <label class='form-control-label px-3'><b>Työkohde</b></label>                                                 
                                    <div style='margin-left: 5px;margin-right: 5px;'>      **<?php echo getLocations(); ?>**
                                        <div id='newLocation'>
                                            <br> 
                                            <input class='mb-3' style='width: 100%;' name='new_location' placeholder='Uusi työkohde...'/>
                                        </div>    
                                    </div>                        
                                </div>
                                
                                <div class='form-group col-sm-10 flex-column d-flex' > 
                                    <label class='form-control-label px-3'><b>Työnkuva</b></label>                                                 
                                    <div style='margin-left: 5px;margin-right: 5px;'>      **<?php echo getdescriptions(); ?> **
                                        <div id='newLocation'><br> <input style='width: 100%;' name='new_description' placeholder='Uusi työnkuva...'/></div>    
                                    </div>                                               </div>                                              <div class='form-group col-sm-10 flex-column d-flex' >                        
                                <label class='form-control-label px-3'><b>Viesti</b></label>                        
                                <div style='margin-left: 5px;margin-right: 5px;'>    
                                    <input style='width: 100%;' name='new_description' value='Jotta voidaan tulostaa viestit'>    
                                </div>    
                                </div>                                              
                                <br>                                                                 
                            </div>   
                            </div>      
                            <input type='hidden' name='action' value='start' />  
                            <input type='hidden' name='msg' value='' />                 
                        </div>                 
                        <div class='row d-flex p-2 '>  
                        <div class='col justify-content-around'>  
                            <button type='submit' class='btn btn-success float-left' name='submit' value='Tallenna'><b>Tallenna</b></button>
                            <button type='submit' class='btn btn-danger float-right' name='submit' value='Tallenna'><b>Poista</b></button> 
                            </div>                 
                        </div>           
                    </form>         
                </div>     
            </div>
        </div> 
    </div> 
</div>";

How I can prevent to html shows those functions as comments "<!--?php echo getLocations(); ?--> & <!--?php echo getdescriptions(); ?-->".

Joporoti
  • 1
  • 1

2 Answers2

-1

Change code like this:


$oupput .= "
<tr data-toggle='modal' data-target='#startWorkTime".$location_row['name'].gmdate("j", $start_day)."' href=''>
    <td class='column7'>".gmdate("j", $start_day).".".gmdate("n", $start_day).".".gmdate("Y", $start_day)."</td>
    <td class='column7'>".$location_row['name']."</td>
    <td class='column7'><a href='https://www.w3schools.com/'>".$row['msg']."</a></td>
    <td class='column7'>".gmdate("G", $sum)."h ".gmdate("i", $sum)."m</td>
</tr>

<div class='modal text-center fade' id='startWorkTime".$location_row['name'].gmdate("j", $start_day)."' > 
    
    <div class='modal-dialog modal-dialog-centered' style='min-width:50%' >   
        
        <div class='modal-content' style='background-color: #fff; border-radius: 10px; border: none; padding: 0; box-shadow: 0 0.46875rem 2.1875rem rgba(90,97,105,0.1), 0 0.9375rem 1.40625rem rgba(90,97,105,0.1), 0 0.25rem 0.53125rem rgba(90,97,105,0.12), 0 0.125rem 0.1875rem rgba; color: #fff;  background-color: rgb(255, 255, 255);'>
            
            <div class='modal-body'>
                <button type='button' class='close text-danger' data-dismiss='modal'>&times;</button>  
                
                <div class=' text-dark'> 
                    <form class='form-card' action='work_time.php' method='post'>     
                        <div class='row justify-content-between text-left'>
                            <div class='form-group col-sm-12 flex-column d-flex'>                        
                                <h6>".$row['start']." ASD ".$row['stop']."Merkinnän id: ".$row['id']."</h6>
                            </div><div class='form-group col-sm-12 flex-column d-flex'>                    
                            <label class='form-control-label px-3'><b>Tiedot</b> <i>Muokkaa klikkaamalla</i></label> 
                            <div style='margin-left: 5px;margin-right: 5px;'>                       
                                <br>                  
                                <div class='form-group col-sm-10 flex-column d-flex' >                        
                                    <label class='form-control-label px-3 '> <b><i class='fa-regular fa-clock text-dark'></i> Aloitus</b></label>
                                    <input style='padding-left: 20px;padding-right: 20px;' type='datetime-local'    name='startdatetime'    value='".date('Y-m-d', strtotime($row['start_date']))."T".date('H:i', strtotime($row['start']))."'         >
                                </div>    
                                
                                <div class='form-group col-sm-10 flex-column d-flex' >                        
                                    <label class='form-control-label px-3 '> <b><i class='fa-regular fa-clock text-dark'></i> Lopetus</b></label>
                                    <input style='padding-left: 20px;padding-right: 20px;' type='datetime-local'    name='stopdatetime' value='".date('Y-m-d', strtotime($row['stop_date']))."T".date('H:i', strtotime($row['stop']))."'>        
                                    <br>
                                    <h6>Tunnit yhteensä: <b>".gmdate("G", $sum)."h ".gmdate("i", $sum)."m</b></h6>
                                </div>
                                
                                <div class='form-group col-sm-10 flex-column d-flex'> 
                                    <label class='form-control-label px-3'><b>Työkohde</b></label>                                                 
                                    <div style='margin-left: 5px;margin-right: 5px;'>      **<?php echo getLocations(); ?>**
                                        <div id='newLocation'>
                                            <br> 
                                            <input class='mb-3' style='width: 100%;' name='new_location' placeholder='Uusi työkohde...'/>
                                        </div>    
                                    </div>                        
                                </div>
                                
                                <div class='form-group col-sm-10 flex-column d-flex' > 
                                    <label class='form-control-label px-3'><b>Työnkuva</b></label>                                                 
                                    <div style='margin-left: 5px;margin-right: 5px;'>".getdescriptions()."
                                        <div id='newLocation'><br> <input style='width: 100%;' name='new_description' placeholder='Uusi työnkuva...'/></div>    
                                    </div>                                               </div>                                              <div class='form-group col-sm-10 flex-column d-flex' >                        
                                <label class='form-control-label px-3'><b>Viesti</b></label>                        
                                <div style='margin-left: 5px;margin-right: 5px;'>    
                                    <input style='width: 100%;' name='new_description' value='Jotta voidaan tulostaa viestit'>    
                                </div>    
                                </div>                                              
                                <br>                                                                 
                            </div>   
                            </div>      
                            <input type='hidden' name='action' value='start' />  
                            <input type='hidden' name='msg' value='' />                 
                        </div>                 
                        <div class='row d-flex p-2 '>  
                        <div class='col justify-content-around'>  
                            <button type='submit' class='btn btn-success float-left' name='submit' value='Tallenna'><b>Tallenna</b></button>
                            <button type='submit' class='btn btn-danger float-right' name='submit' value='Tallenna'><b>Poista</b></button> 
                            </div>                 
                        </div>           
                    </form>         
                </div>     
            </div>
        </div> 
    </div> 
</div>";
Tural Rzaxanov
  • 783
  • 1
  • 7
  • 16
-1

Those tags are HTML encoded because you have them inside a double-quoted string. PHP is interpreting the tags as actual PHP open/close tags, and since they're in a string, they just output as-is. To fix this, you can use heredoc syntax instead:

$output .= <<<HTML
...
<?php echo getLocations(); ?>
...
HTML;

This will allow actual PHP code to be interpreted within the string.

It seems you have a deeper issue causing the PHP to not be parsed at all. I would double-check your PHP file extension and server configuration to ensure PHP is being parsed correctly.

HKTE
  • 167
  • 5