Want to delete row from DB by selecting dropdown menu
Posted: Sat Mar 07, 2009 12:42 am
Hi,
I am new to this forum and beginner in PHP.
I have following code. I am able show values in dropdown list but i am not able to select the value and delete it from DB.
Please suggest me what is wrong into this.
Thanks
Amit
I am new to this forum and beginner in PHP.
I have following code. I am able show values in dropdown list but i am not able to select the value and delete it from DB.
Please suggest me what is wrong into this.
Thanks
Amit
Code: Select all
<?
// Connect database
mysql_connect("localhost","root","");
mysql_select_db("ItcPolicy");
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form id="form1" name="form1" method="POST" action="delete.php">
<? echo "List Of Policies:<br>";?>
<select name="select">
<option value="">--- Select ---</option>
<?
$q1=mysql_query("SELECT PolicyName, FileName FROM listofpolicies;");
// Show records by while loop.
while($q1arr = mysql_fetch_assoc($q1)){
?>
<option value="<? echo $q1arr['FileName']; ?>" <? if($q1arr['FileName']==$select){ echo "selected"; } ?>><? echo $q1arr['PolicyName']; ?></option>
<?
// End while loop.
}
?>
</select>
<input type="submit" name="Submit" value="Select" />
</form>
<p>
<?
// If you have selected from list box.
if(isset($select)&&$select!=""){
$select=$_POST['Select'];
echo $select;
}
if(isset($select) && $select!=""){
// Get records from database (table "name_list").
$q2=mysql_query("DELETE * FROM listofpolicies where FileName='Catamaran.pdf';");
//$q1arr=mysql_fetch_assoc($q2);
?>
<? echo $q1arr['PolicyName']; ?>
<?
// End if statement.
}
// Close database connection.
mysql_close();
?>
</p>
</body>
</html>