I asked a question yesterday about a problem with PHP on deleting a row from SQL, using dropdown buttons IDs : Adding and accessing buttons IDs in a PHP-generated table
I managed to correct some errors, use a for each instead of a while, ... But now I have different problems : "Warning illegal string offset" and probably others I'm not aware of.
Here's the code : (problems are below)
<?php
$con=mysqli_connect("localhost","root","icare","icare1");
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM magasin");
echo "<table border='1'>
<tr>
<th>Code</th>
<th>Adresse IP</th>
<th>Adresse ADS</th>
<th>Région</th>
<th>Adresse</th>
<th>Nom du directeur</th>
<th>Mail</th>
<th>Téléphone</th>
<th>GTC</th>
<th>Date d'installation</th>
</tr>";
// PROBLEMS START HERE
$data = mysqli_fetch_array($result);
?>
<table>
<?php foreach ($data as $key => $row):?>
<tr>
<td>
<div class='dropdown-content'>
<button class='dropbtn'>▶</button>
<a href="delete.php?Code='<?php echo $row['Code']?>'">Supprimer</a>
</div>
</td>
<?php
$dat=array('AdresseIP' => $row['AdresseIP'], 'AdresseADS' => $row['AdresseADS'], 'Region' => $row['Region'],
'Adresse' => $row['Adresse'], 'NomDirecteur' => $row['NomDirecteur'], 'Mail' => $row['Mail'], 'Tel' => $row['Tel'],
'Gtc' => $row['Gtc'], 'DateInstall' => $row['DateInstall']);
?>
<td><div><?php echo $dat('AdresseIP');?></div></td>
<td><div><?php echo $dat('AdresseADS');?></div></td>
<td><div><?php echo $dat('Region');?></div></td>
<td><div><?php echo $dat('Adresse');?></div></td>
<td><div><?php echo $dat('NomDirecteur');?></div></td>
<td><div><?php echo $dat('Mail');?></div></td>
<td><div><?php echo $dat('Tel');?></div></td>
<td><div><?php echo $dat('Gtc');?></div></td>
<td><div><?php echo $dat('DateInstall');?></td>
</tr>
<?php endforeach ?>
</table>
<?mysqli_close($con);?>
I get data from the database, store them in $result, then $data. Then for each row of $data, I display data in my table cells, starting with a dropdown button. This dropdown menu redirects to a "Delete" PHP script, which deletes the row linked to the dropdown button.
I get the illegal string offset error and I don't know why...
Also, this line doesn't seem to work because it prints ' 1'">Supprimer '
<a href="delete.php?Code='<?php echo $row['Code']?>'">Supprimer</a>
I'm kind of lost here and being new into PHP doesn't really help.