devimohan1988 Posted April 10, 2013 Share Posted April 10, 2013 <?php include('connection.php'); if(isset($_GET['id'])) { $id=$_GET['id']; $query1=mysql_query("delete from news where id='$id'"); if($query1) { header('location:news_list.php'); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/276771-how-can-i-delete-value-in-database-through-html-form/ Share on other sites More sharing options...
computermax2328 Posted April 10, 2013 Share Posted April 10, 2013 Do you have your HTML form? There are like 10 different ways you can do this. Post your HTML form and I can help you with it. Quote Link to comment https://forums.phpfreaks.com/topic/276771-how-can-i-delete-value-in-database-through-html-form/#findComment-1423916 Share on other sites More sharing options...
devimohan1988 Posted April 11, 2013 Author Share Posted April 11, 2013 My html form: news_list.php   <?php include("admin.php"); include("connection.php"); $sql=mysql_query("select * from news order by id"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head>  <body> <!--<form name="frm" action="news_delete.php" method="post">--> <div align="center" style="width:700px; height:auto; float:left;border:solid 1px #DCDCDC; margin-top:20px;"><!--main div-->  <div align="center" style="width:700px; height:auto; float:left;border:solid 1px #DCDCDC;"> <div align="center" style="width:50px; height:auto; float:left;border:solid 1px #DCDCDC;">NO</div> <div align="center" style="width:300px; height:auto; float:left;border:solid 1px #DCDCDC;">NEWS</div> </div>  <div align="center" style="width:300px; height:auto; float:left;border:solid 1px #DCDCDC;"> <?php if($sql>0) { while($row=mysql_fetch_array($sql)) { $id=$row['id']; $msg=$row['details']; ?>   <div align="center" style="width:700px; height:auto; float:left;border:solid 1px #DCDCDC;"> <div align="center" style="width:50px; height:auto; float:left;border:solid 1px #DCDCDC;"><?php echo $id?></div> <div align="center" style="width:300px; height:auto; float:left;border:solid 1px #DCDCDC;"><?php echo $msg?></div> <div align="center" style="width:100px; height:auto; float:left;border:solid 1px #DCDCDC;"><a href="news_edit.php">EDIT</a></div> <!--<div align="center" style="width:100px; height:auto; float:left;border:solid 1px #DCDCDC;"><button onclick="window.location.href='news_delete.php'">DELETE</button></div>--> <div align="center" style="width:50px; height:auto; float:left;border:solid 1px #DCDCDC;"><a href="news_delete.php?id=$id">delete</a></div> <!--<div align="center" style="width:50px; height:auto; float:left;border:solid 1px #DCDCDC;"><input name="delete" type="submit" value="DELETE"/></div> --> <?php } } ?> </div>  </div>   <div align="center" style="width:100px; height:auto; float:left; margin-left:550px;"><a href="news.php">ADD NEW</a></div> </div><!--main div ends--> <!--</form>--> </body> </html>  news_delete.php   <?php include('connection.php'); if(isset($_GET['id'])) { $id=$_GET['id']; $query1=mysql_query("delete from news where id='$id'"); if($query1) { header('location:news_list.php'); } } ?>  on clicking the button(delete) control rem,aining in news_list page.what is the problem in this code? Quote Link to comment https://forums.phpfreaks.com/topic/276771-how-can-i-delete-value-in-database-through-html-form/#findComment-1424090 Share on other sites More sharing options...
trq Posted April 11, 2013 Share Posted April 11, 2013 You have most of the bits required for this to work commented out. Quote Link to comment https://forums.phpfreaks.com/topic/276771-how-can-i-delete-value-in-database-through-html-form/#findComment-1424092 Share on other sites More sharing options...
devimohan1988 Posted April 11, 2013 Author Share Posted April 11, 2013 sir, i cannt get you.please explain. i commented 2 delete buttons.bt 1 delete button which is working is not commented. next i commented form description. i think form can be optional because using href i called the page where the control has to move. Quote Link to comment https://forums.phpfreaks.com/topic/276771-how-can-i-delete-value-in-database-through-html-form/#findComment-1424094 Share on other sites More sharing options...
devimohan1988 Posted April 11, 2013 Author Share Posted April 11, 2013 i removed comment of the form. <div align="center" style="width:50px; height:auto; float:left;border:solid 1px #DCDCDC;"><a href="news_delete.php?id=$id">delete</a></div> removed ?id=$id from a href.now the connection is moving to news_delete.php.bt cannt delete the value. Quote Link to comment https://forums.phpfreaks.com/topic/276771-how-can-i-delete-value-in-database-through-html-form/#findComment-1424095 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.