flexybash Posted December 4, 2010 Share Posted December 4, 2010 Okey so i made a table that you put your name,author,and message when you submit it , it echoes a table with the name,author and message written (and it also echoes a delete buttom,so delete this post oif necessary) im new to php and i have been with this problem for a couple of weeks so i guess its time to ask for some help the problem is that i dunnot know how to make my delete buttom work! i tried if statement but it dosent work i also tried ternary operation and dint work :S i read that there is something like $post[iD](and this is supposed to get the ID of the post submmited, and delete it) im not sure, im so confused! help! XD this is the code <?php $tittle=$_POST['tittle']; $author=$_POST['author']; $message=$_POST['message']; if ($_POST['submitnews']){ $currentdate= date("y-m-d"); $currenttime=date("H:i:s",strtotime("-6 hours")); $post=mysql_query("INSERT INTO news VALUES('','$tittle','$author','$message','$currentdate','$currenttime')"); echo"Posted!"; } $select=mysql_query("SELECT * FROM news ORDER BY id DESC"); while ($row= mysql_fetch_assoc($select)) { $id=$row['id']; $tittle=$row['tittle']; $author=$row['author']; $message=$row['message']; $date=$row['date']; $time=$row['time']; if ($_SESSION['admin']) { echo " <table width='488px' id='news_table'> <tr> <td> </td> <td> <center><font size='5'>$tittle</font></center><br> </td> </tr> <tr> <td> </td> <td> $message </td> </tr> <tr> <td> </td> <td> <font size='1'>Posted By:<font color='green'>$author</font> on <font color='gray'>$date</font> at <font color='gray'>$time</font></font> <input name='delete' type='submit' value='delete'> <td> </td> </tr><br><br> </table>"; Link to comment https://forums.phpfreaks.com/topic/220617-problem/ Share on other sites More sharing options...
dragon_sa Posted December 4, 2010 Share Posted December 4, 2010 you need to put the delete button in a form to use like that so <input name='delete' type='submit' value='delete'> becomes <form action='' method='post' target='_self'><input type='hidden' name='id' value='$id'><input name='delete' type='submit' value='delete'></form> then you need at the top of your page if ($_POST['delete']) { $deleteID=$_POST['id']; $sql = "DELETE FROM news WHERE id='$deleteID'"; $result = mysql_query($sql); } that should get you started Link to comment https://forums.phpfreaks.com/topic/220617-problem/#findComment-1142797 Share on other sites More sharing options...
flexybash Posted December 4, 2010 Author Share Posted December 4, 2010 Thank you very much dragon u solved my problem i will study this code! Link to comment https://forums.phpfreaks.com/topic/220617-problem/#findComment-1142898 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.