unexpected php error

0

I have the following error in my form, I know I'm missing something but I do not know where. look:

<?php if(Session::getUID()!=""):?>
			<?php
			$u=null;
			if(Session::getUID()!=""){
			  $u = PacientData::getById(Session::getUID());
			  $user = $u->name." ".$u->lastname." ".$u->username." ".$u->email;
			  ?>
			<table class="table table-bordered table-hover">
			<thead>
			<th>Nombre completo</th>
			<th>Usuario</th>
			<th>Email</th>
			<th>Activo</th>
			<th></th>
			</thead>
			<?php
			foreach($users as $user){
				?>
				<tr>
				<td><?php echo $user->name." ".$user->lastname; ?></td>
				<td><?php echo $user->username; ?></td>
				<td><?php echo $user->email; ?></td>
				<td>
					<?php if($user->is_active):?>
						<i class="glyphicon glyphicon-ok"></i>
				</td>
				<td style="width:150px;"><a href="index.php?view=editpacient&id=<?php echo $user->id;?>" class="btn btn-warning btn-xs">Editar</a>
				</tr>
				<?php

			endif;

		}

		?>

	</div>
</div>

Where could the fault be?

    
asked by Julio Angel Mejia Tejada 04.01.2019 в 23:04
source

1 answer

1

The error is that there is a if that you are not closing, it may be this:

                <?php if($user->is_active):?>

so you can understand the logic of your program.

You have a very confusing code, for two main reasons:

  • mixes two styles of if which is not recommended
  • too many openings / closures of PHP blocks to combine with HTML, is lawful, but produces horrible code. I recommend that you concatenate, using a single PHP block.

I propose this, you will appreciate the difference in terms of clarity:

<?php 
    if(Session::getUID()!="") {
            $u=null;
            if(Session::getUID()!=""){
              $u = PacientData::getById(Session::getUID());
              $user = "$u->name $u->lastname $u->username $u->email";
              $html="<table class=\"table table-bordered table-hover\">";
              /* Empezamos a concatenar... NÓTESE el uso de .= */
              $html.="<thead>
              <th>Nombre completo</th>
              <th>Usuario</th>
              <th>Email</th>
              <th>Activo</th>
              <th></th>
              </thead>";
                 foreach($users as $user){
                    $html.="<tr>";
                    $html.="<td>$user->name $user->lastname </td>";
                    $html.="<td>$user->username</td>";
                    $html.="<td>$user->email</td>";
                    $statusActive=( $user->is_active ) ? "<i class=\"glyphicon glyphicon-ok\"></i>" : "";
                    $html.="<td>$statusActive</td>";
                    $url="index.php?view=editpacient&id=$user->id";
                    $lastCell="<td style=\"width:150px;\"><a href=\"$url\" class=\"btn btn-warning btn-xs\">Editar</a>";
                    $html.="<td>$lastCell</td>";
                    $html.="</tr>";             
                }
            }
    }
    echo $html;
    /*
        *Ojo a esto, dejo los div fuera de la variable $html
        *porque no sé de dónde vienen, pero hace pensar que 
        *es necesario mejorar aún la lógica de tu programa
        *construyendo todo  en la misma variable y haciendo echo al final
    */
    echo "</div>";
echo "</div>";
?>

I have used other techniques, such as the use of ternary operators. You will see that I have preferred to build the URL of the link separately, it is a personal option (I do not like writing endless lines of code).

There are other practices not recommended in your code, such as applying styles directly, currently it is recommended to use classes and manage styles via CSS.

I hope it serves you.

    
answered by 05.01.2019 / 02:23
source