I'm doing a little php + mysql for deleting rows in my database, the problem that when I press the button and nothing happen. I would appreciate your help.
This PHP shows a list of courses that a type of employee has to do, the delete button should delete the course of the list that you select it.
for example
cargocurso.php?id=1
shows the type of employee, for example:
Sales Manager
and in a table the courses related with that type of empleyee:
1 | Sales | (delete button)
<?php
$link = mysql_connect("localhost", "root","123456");
mysql_select_db("ecl", $link);
if (isset($_GET['id'])) {
$id=$_GET['id'];;
$sql = mysql_query("select k.idcargo, c.fullname, k.nombre_cargo, d.cursoid, d.id from mdl_course as c
inner join mdl_user_cursos_asoc as d on c.id = d.cursoid
inner join mdl_user_cargo as k on d.cargoid = k.idcargo where k.idcargo=$id", $link);
if (isset($_POST['delete'])) {
$idasoc = $_POST['idasoc'];
$sql2 = "DELETE FROM mdl_user_cursos_asoc WHERE id = '.$idasoc.'";
$result = mysql_query($sql2);
echo "has been deleted.";
}
if(mysql_num_rows($sql) == 0) {
echo "No hay cursos asociados";
} else {
$cargnombre = mysql_fetch_array($sql);
echo $cargnombre[2]."</br></br>";
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>";
echo "<table border='1px'>";
while ($row = mysql_fetch_array($sql)) {
echo "<tr>";
echo "<input type='hidden' name='idasoc' value = '.$row[4].'>";
echo "<td>$row[1]</td>";
echo "<td><input type='submit' name='delete' value='Eliminar'></td>";
echo "</tr>";
}
echo "</table>";
echo "</form>";
}
}
?>
Thanks for you help!