Jump to content

Problem


flexybash

Recommended Posts

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 :D

 

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.