Jump to content

MySql Delete Comment


Recommended Posts

ok so i have working code that will display message/subject from a database. here it is:

[code]<?php
include('config.php');

$db = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);

$query  = "SELECT csubject, cmessage FROM deltest1";
$result = mysql_query($query) or die('Error, query failed ##1');

$htmlsubbefore="(html table code...etc)";
$htmlsubafter="(html table code...etc)";
$htmlbodbefore="(html table code...etc)";

echo "<table>";
while($row = mysql_fetch_row($result))
{
    $Subject    = $row[0];
    $Message = $row[1];

    echo $htmlsubbefore . $row[0] . $htmlsubafter.
        $htmlbodbefore . $row[1] . $htmlbodafter . "</table>";
}
  $htmlbodafter="</td>/tr></table>";
?>[/code]

now what that does is keep displaying messages/subjects in the databases until their is no more. screenshot:
[img]http://csscobalt.com/uploads/table_php_help_v01.jpg[/img]

and now what i want to add is an image and when you click on that image it will delete that (and only that) comment.
and if i add: [code]echo "<img src=\"http://image.fpsbanana.com/ico/del.gif\"></a>";[/code] right below this:
[code]  echo $htmlsubbefore . $row[0] . $htmlsubafter.
        $htmlbodbefore . $row[1] . $htmlbodafter . "</table>";[/code]

then the image will appear under every comment. screenshot:
[img]http://csscobalt.com/uploads/table_php_help_v02.jpg[/img]
(the trash can is the image)

now i found some code that will delete the database (was used for image galary)
[code]        $sql = "DELETE FROM deltest1
                WHERE img_id = {$_GET['imgId']} AND im_album_id = {$_GET['album']}";
        mysql_query($sql) or die('Delete album failed. ' . mysql_error());    [/code]
but i can't get it to work and i need help. please help?
Link to comment
Share on other sites

[quote author=Jocka link=topic=116750.msg475855#msg475855 date=1164833204]
1) just a guess.. is im_album_id supposed to be img_album_id ?
2) And was the image coming below the message a problem? if so just throw the link BEFORE the </table> in the echo statement before.
[/quote]
1) sure
2) no, i WANT that trashcan image to be their. lol that is what you are going to have to click to get that post deleted
Link to comment
Share on other sites

no, you dont understand.
that code was literally copied exactly from an image galery code.

i mean i was just using that as an example, i am trying to figure out the logic of this

like i mean is that code correct? would that code actually work?

also my main delema is where do i put that code and how do i get the pressing of the image to trigger it!
Link to comment
Share on other sites

OOOOHHHHHHHHH gotcha

Ok this:
echo "<img src=\"http://image.fpsbanana.com/ico/del.gif\"></a>";

to this:
echo "<a href='yourpagename.php?act=del&id=" . $MESSAGE_ID . "' title='Delete'><img src=\"http://image.fpsbanana.com/ico/del.gif\"></a>";

now on that page (can be anywhere on the page above the output of the messages):
if(isset($_GET['act']) && $_GET['act'] == 'del'){
// Do your checks to make sure this is THIS users message
$sql = "DELETE FROM table WHERE id='" . $_GET['id'];
mysql_query($sql) or die(mysql_error()); // gives errors
}
Link to comment
Share on other sites

ok awesome, i'l try it in a sec, but 1 question:

on your code here:
if(isset($_GET['act']) && $_GET['act'] == 'del'){
when you say GET['[b][u]act[/u][/b]'], is it going to be "Act" for all times i do this? or is it the name of something?

and here:
== 'del'
where are you getting 'del' from?
because you titled your image:
title='Delete'
so did you mean:
== 'Delete'
??
(im just trying to understand what u did)
Link to comment
Share on other sites

oh i see, act came from the ...?act=... thing. ok. but what about:

== 'del'
where are you getting 'del' from?
because you titled your image:
title='Delete'
so did you mean:
== 'Delete'
??

also where in my current code do i put this code? in my loop or outside?
[code]if(isset($_GET['act']) && $_GET['act'] == 'del'){
// Do your checks to make sure this is THIS users message
$sql = "DELETE FROM table WHERE id='" . $_GET['id'];
mysql_query($sql) or die(mysql_error()); // gives errors
}[/code]
Link to comment
Share on other sites

update:
if i use your code:
[code] $sql = "DELETE FROM deltest WHERE id='" . $_GET['id'];[/code]
i get this:
[quote]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''' at line 1[/quote]
so:
if i replace it with:
[code]  $sql = "DELETE FROM deltest1 WHERE id=" . $_GET['id'];[/code]
i get:
[quote]Query was empty[/quote]

and if i replace it with this:
[code]  $sql = "DELETE FROM deltest1 WHERE id='" . $_GET['id'] . "'";[/code]
i get:
[quote]Unknown column 'id' in 'where clause'[/quote]

little help?

i mean where is it even getting:
$_GET['id'] !??
Link to comment
Share on other sites

someone PLEASE help!???

for reference, here is the EXACT code i'm using:

[code]<?php
$db = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);

$query  = "SELECT csubject, cmessage FROM deltest1";
$result = mysql_query($query) or die('Error, query failed ##1');
$htmlsubbefore="(html table code...etc)";
$htmlsubafter="(html table code...etc)";
$htmlbodbefore="(html table code...etc)";

//deltion check
if(isset($_GET['act']) && $_GET['act'] == 'del'){
// Do your checks to make sure this is THIS users message
$sql_delete = "DELETE FROM deltest1 WHERE id=$id";
//  $sql_delete = "DELETE FROM deltest1 WHERE id='" . $_GET['id'] . "'";
mysql_query($sql_delete) or die(mysql_error()); // gives errors
}

echo "<table>";
while($row = mysql_fetch_row($result))
{
    $Subject    = $row[0];
    $Message = $row[1];

    echo $htmlsubbefore . $row[0] . $htmlsubafter.
        $htmlbodbefore . $row[1] . $htmlbodafter . "</table>";

echo "<a href='delete3.php?act=del&id=" . $MESSAGE_ID . "' title='Delete'><img src=\"http://image.fpsbanana.com/ico/del.gif\"></a>";
echo $id_loop1;
// $MESSAGE_ID  $_GET['id']
}
  $htmlbodafter="</td>/tr></table>";
?>[/code]
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.