Hey all this is a pretty simple question, basically I connect to a mysql database, and iterate a list of names like this:
$result = mysql_query("SELECT * FROM Students");
echo "<table border=\"1\">";
while($row = mysql_fetch_array($result))
{
print "
<tr>
<td>
"
. $row['Student'] .
"
</td>
<td>
<form name=\"FRMdelete" . $row['Student'] . "\" action=\"deletestudent.php\" method=\"POST\" style=\"margin-bottom:0;\">
<input name=\"delete\" type=\"submit\" id=\"" . $row['Student'] . "\" value=\"Delete\" OnClick=\"return confirm('Are you sure you want to Delete " . $row['Student'] . "?')\">
</form>
</td>
</tr>
";
}
echo"</table>";
mysql_close($con);
Then I using POST, I pass the name of the student from the ID of the input to deletestudent.php, which looks like this:
<?php
$studentremoved = $_POST['delete'];
$sql = "DELETE FROM Students WHERE Student='" . $studentremoved . "'";
$con = mysql_connect("localhost","root","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_query($sql);
mysql_close($con);
header("Location: ".$_SERVER['HTTP_REFERER']);
?>
For some reason the scripts execute without throwing and errors to my debugger, but it doesn't delete the record =/
What am I missing, I know its probably obvious. Sorry for the sloppy code, I am a beginner =/