0

I saved a value as a cookie and then checked if there exists in the perfiles_vinculados table to get all the data that has the same id in the perfil table.

Then I create an array of the $vinculado result and show it in a HTML table as a row.

The problem is that the console returns:

Catchable fatal error:
Object of class mysqli_result could not be converted to string in C:\xampp\htdocs\miramonteapp\api\modal.php

The cookie:

document.cookie = "vinculaciones=" + $("#mod_id_perfil").val();

PHP:

//querys

<?php

include 'api/conexion.php';
$ides = $_COOKIE['vinculaciones'];
$juridicos = "SELECT perfil_juridica FROM perfiles_vinculados where  perfil_fisica = '$ides'";
$con = mysqli_query($conexion, $juridicos);
$vinculado = mysqli_query($conexion, "SELECT * FROM perfil where  id = '$con'");

?>

//table

<?php 
while($reg = mysqli_fetch_array($vinculado)) {
    $id = $reg['id'];  
?>
<tr id="<?php echo " tr_ ".$reg['id']; ?>">
  <td class="" data-id="<?php echo $reg['usuario'] ?>">
    <?php echo $reg['nombre']; ?>
  </td>
  <td class="" data-id="<?php echo $reg['usuario'] ?>">
    <?php echo $reg['cuit']; ?>
  </td>
  <td class="td-actions text-right">
    <button type="button" rel="tooltip" class="btn btn-danger">
      <i class="material-icons">close</i>
    </button>
  </td>
<?php } ?>
Dharman
  • 30,962
  • 25
  • 85
  • 135
shios
  • 67
  • 8

1 Answers1

1

You have to learn about join sql statement.

As for you current approach, first you need to fetch perfil_juridica value from a result of $juridicos execution and then pass this value to your second query:

// first query
$juridicos = "SELECT perfil_juridica FROM perfiles_vinculados where  perfil_fisica = '$ides'";
$result = mysqli_query($conexion, $juridicos);
$row = mysqli_fetch_array($result);
$perfil_juridica = $row['perfil_juridica'];
// second query
$vinculado = mysqli_query($conexion, "SELECT * FROM perfil where  id = '$perfil_juridica'");

What you should do next is move to prepared statements instead of putting unsafe values into query texts. This question will help you.

u_mulder
  • 54,101
  • 5
  • 48
  • 64