Error expanding PHP / MySQL details

0

In PHP / SQL, I have to show the details of some employees of a company, which are stored in the MySQL database. Right now, the code that I have developed is the following:

employees.php

<?php
  $host = "oraclepr.uco.es";
  $username = "i52calei";
  $password = "***";
  $database = "i52calei";

  $conn = new mysqli ($host, $username, $password, $database);
  if ($conn->connect_error)
    die ($conn->connect_error);

  $sql = "SELECT nombre, apellidos, edad, DNI, salario, telefono, direccion FROM empresa";
?>

<table border=1>
<tr>
  <th>Nombre</th>
  <th>Apellidos</th>
</tr>

<?php
  $rows = $conn->query($sql);
  if(!$rows)
    die($conn->error);

  foreach($rows as $row){
    echo '<tr><td>'.$row["nombre"].'</td><td>'.$row["apellidos"].'</td><td><a href="detalles_empleado.php?nombre='.urlencode($row["nombre"]).'">Ver detalles</a></td></tr>';
  }
  echo "</table>";
  $conn = null;
?>

details_employee.php

<?php
  $host = "oraclepr.uco.es";
  $username = "i52calei";
  $password = "***";
  $database = "i52calei";

  $conn = new mysqli ($host, $username, $password, $database);
  if ($conn->connect_error)
    die ($conn->connect_error);

  $sql = "SELECT * FROM empresa where nombre=".$_GET["nombre"];

  $rows = $conn->query ($sql);
  if (!$rows)
    die ($conn->error);

  $row=$rows->fetch_assoc ();
?>

<p><strong>Nombre: </strong><?php echo $row["nombre"]?></p>
<p><strong>Apellidos: </strong><?php echo $row["apellidos"]?></p>
<p><strong>Edad: </strong><?php echo $row["edad"]?></p>
<p><strong>DNI: </strong><?php echo $row["DNI"]?></p>
<p><strong>salario: </strong><?php echo $row["salario"]?></p>
<p><strong>telefono: </strong><?php echo $row["telefono"]?></p>
<p><strong>Direccion: </strong><?php echo $row["direccion"]?></p>

<br/>

<a href="empleados.php">Lista de Empleados</a>
<?php
  $conn = null;
?>

Now, the error that arises is:

  

Unknown column 'employeeName' in 'where clause'

I think the error is in employees.php in the line below, but I would not know how to solve it either

echo '<tr><td>'.$row["nombre"].'</td><td>'.$row["apellidos"].'</td><td><a href="detalles_empleado.php?nombre='.urlencode($row["nombre"]).'">Ver detalles</a></td></tr>';

I emphasize that the table with the employees saved in the database shows it without problems, it is by expanding the personal information of an employee of the table when the error occurs

Thanks in advance !!

    
asked by Nacho 25.10.2017 в 14:39
source

1 answer

1

You have a problem in the concatenation of your query, in such a way that you are trying to search with the parameter 'nameEmployee' that does not exist in your table. You can print the query that you are executing with a var_dump ($ query) or with a simple echo $ query, this will tell you if you are assembling the query correctly.

    
answered by 26.10.2017 в 01:01