Home > Mobile >  syntax error, unexpected double-quote mark PHP
syntax error, unexpected double-quote mark PHP

Time:05-31

I am creating a class to create targets of type input text but it shows me the error

syntax error, unexpected double-quote mark PHP

<?php
class OBJElementosForm {
 

  function _construct(){

  }

  function CrearInputText ($Lista,$nombre){
    $opcion = "";
    foreach ($Lista as $valor)
    {
        $texto = '<label>'.$valor.'</label>';
        $opcion=$texto.'<input type="text" id='".$valor."'name='".$nombre."' value='".$valor."'>
        <br>'.$opcion;
    }
    


}

 
}
?>

CodePudding user response:

This should be okay:

$opcion=$texto.'<input type="text" id="'.$valor.'" name="'.$nombre.'" value="'.$valor.'">
<br>'.$opcion;

The problem is you've started by a single quote, and used double quotes to close it! I recommend you to use an IDE or at least a good editor like VSCode to check and reformat your code.

CodePudding user response:

You could try with something like this:

$opcion=$texto."<input type='text' id='$valor' name='$nombre' value='$valor'><br/>$opcion";
  •  Tags:  
  • php
  • Related