Hi I'm a newbie to PHP and please help me understand where I've gone wrong. Below is an extraction of the lengthy code I have where I'm trying to get SQL database values to a table with checkboxes adding in-front, allowing users to pick and delete the record they want. My issue is once a record is picked through the checkbox and hit delete, the record isn't getting deleted.
The Validation bit
is what I have in the code to delete the checkbox picked values. Populating checkboxes for each data row extracted from the database:
will tell you how I'm getting the checkboxes via the loop.
If the information provided isn't sufficient please highlight. Thank you. Validation bit :
if(isset($_POST['deletez']))
{
foreach($_POST['deletez'] as $wec)
{
$db = mysqli_connect('localhost', 'root', '', 'regional_data');
if(mysqli_connect_errno()) {die('The connection to the database could not be established.');}
$rW = mysqli_query($db,"DELETE * FROM brands WHERE bname ='$wec'");
}
}
Populating checkboxes for each data row extracted from the database:
while ($reK = mysqli_fetch_array($runBrands))
{
$wec = $reK['bname'];
echo "<tr class='brndTab'>";
echo "<tr>"
."<td><input type='submit' name='deleteR' id='deleteR' value='Delete.'></td>".
"</tr>";
echo "</table>";
echo "<td class='brndTab'>".$reK["bname"]."</td>";
echo "<td class='brndTab'>".$reK["bvariant"]."</td>";
echo "<td class='brndTab1'>".$reK["bsku"]."</td>";
echo "<td class='brndTa'><input type='checkbox' name='deletez[]' value='$wec'></td>";
echo "</tr>";
}