I'm suppose to select any row from my database and delete the row but there is some problems with my coding.
Can anyone help me to amend my php code?
Thank you
<form method="post" action="deletestudent_p.php">
<?
// connect to MySQL database server
$connection = mysql_connect("localhost", "root", "") or die("Could not connect to MySQL " .mysql_error() );
// select the specified database
$selection = mysql_select_db("studentwww") or die("Unable to select database. " .mysql_error());
$submit = $_POST["submit"];
if($submit=="Search")
{
if(isset($_POST["MatricNo"]))
{ // create the query
$Matrik = $_POST["MatricNo"];
$sql = "SELECT * from addstudent where Matric ='$Matrik'";
// execute query
$result = mysql_query($sql) or die("SQL select statement failed");
// retrieves a row data and returns it as an associative array
if($row=mysql_fetch_array($result))
{ // display direct from array
echo "Matric No : $row[Matric] <br>";
echo "Student Name : $row[StudentName]<br>";
echo "Address : $row[Address]<br>";
echo "<input type='hidden' name='MatricNo' value='$row[Matric]'>";
echo "<input type ='submit' name='submit' value='confirm?'>"; }
else { echo "No record found"; }
}
}
if($submit=="confirm?")
{ $Matric = $_POST["MatricNo"];
$sql= "DELETE FROM Student WHERE Matric = '$Matric'";
$result = mysql_query($sql);
echo "<hr><h2>Record Deleted</h2><br>";
} ?></form></body></html>