Paste PHP Code into Heredoc for Good Choice

Hi, currently working on a page to get a form that matches my database. I want the selected "TYPE" option to be selected according to$client['CLT_type']

This is what my real code looks like (and what I tested) But I am getting this error:

Parsing error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING at 24

24 is my $ select line

if($client = $requeteClt->fetch()) {

        $select = "<?php if($client['CLT_type']==2) echo 'selected'; ?>";

            <div id='res' height='800px'></div>
            <form id='form' name='form' method='POST' action='modifierClientScript.php' style='width:100%;'>
                <h2 style="text-align:center;">Modification du client {$client['CLT_libelle']}</h2>
                    <label for='montant'>Nom :</label>
                    <input type='text' value='{$client['CLT_libelle']}' name='nom' id='nom'>
                    <span class="error" id="nomErr"></span>
                <label for='type'>Segmentation Client :</label>
                    <SELECT name='type' id='type'>
                        <optgroup label="Publics">
                            <OPTION value='1'>Etat
                            <OPTION value='2' {$select}>Collectivité
                            <OPTION value='3'>Entreprise publique
                        <optgroup label="Privés">
                            <OPTION value='4'>Entreprise de service
                            <OPTION value='5'>Entreprise industrielle
                            <OPTION value='6'>Autres

                    <input type='button' name='submit' id='submit' value='Modifier le client'>


So is it possible to add PHP code to the Heredoc or do I need to manipulate my page in a different way? thank


source to share

1 answer

To fix bugs.

$select = ($client['CLT_type']==2) ? 'selected' : null;


Never use tags <?php

in tags <?php




All Articles