JustinMs66@hotmail.com Posted November 29, 2006 Share Posted November 29, 2006 ok so i have working code that will display message/subject from a database. here it is:[code]<?phpinclude('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? Quote Link to comment Share on other sites More sharing options...
Jocka Posted November 29, 2006 Share Posted November 29, 2006 just a guess.. is im_album_id supposed to be img_album_id ?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 Link to comment Share on other sites More sharing options...
JustinMs66@hotmail.com Posted November 29, 2006 Author Share Posted November 29, 2006 [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) sure2) 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 Quote Link to comment Share on other sites More sharing options...
Jocka Posted November 29, 2006 Share Posted November 29, 2006 Ok. Did the img_album_id fix it? or still nothing.$sql = "DELETE FROM deltest1 WHERE img_id='".$_GET['imgId']."' AND img_album_id='".$_GET['album']."'";change the $sql string to this.. that might get it done 2 Quote Link to comment Share on other sites More sharing options...
JustinMs66@hotmail.com Posted November 29, 2006 Author Share Posted November 29, 2006 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 thislike 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! Quote Link to comment Share on other sites More sharing options...
Jocka Posted November 29, 2006 Share Posted November 29, 2006 OOOOHHHHHHHHH gotchaOk 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} Quote Link to comment Share on other sites More sharing options...
JustinMs66@hotmail.com Posted November 29, 2006 Author Share Posted November 29, 2006 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) Quote Link to comment Share on other sites More sharing options...
Jocka Posted November 29, 2006 Share Posted November 29, 2006 it doesn't have to be act, it's whatever you set it to be. It can be ANYTHING. Think of it like this:$page?[b]key=value[/b]key is "act" and value is what act is supposed to do. You can make it anything u desire Quote Link to comment Share on other sites More sharing options...
JustinMs66@hotmail.com Posted November 29, 2006 Author Share Posted November 29, 2006 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] Quote Link to comment Share on other sites More sharing options...
Jocka Posted November 29, 2006 Share Posted November 29, 2006 yourpagename.php?act=[b]del[/b]&id=" . $MESSAGE_ID . "del is the value part. To add more keys and values after the first initial one you have to follow with &. such as ?act=del[b][i]&[/i]id=" . $MESSAGE_ID . "[/b] Quote Link to comment Share on other sites More sharing options...
Jocka Posted November 29, 2006 Share Posted November 29, 2006 do it before you begin the loop to delete the message prior to pulling the messages from the database Quote Link to comment Share on other sites More sharing options...
JustinMs66@hotmail.com Posted November 30, 2006 Author Share Posted November 30, 2006 ok cool but i dont see how it gets the comment ID.i mean how does it know, unless its in the loop, which comment its deleteing? Quote Link to comment Share on other sites More sharing options...
JustinMs66@hotmail.com Posted November 30, 2006 Author Share Posted November 30, 2006 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'] !?? Quote Link to comment Share on other sites More sharing options...
JustinMs66@hotmail.com Posted December 4, 2006 Author Share Posted December 4, 2006 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 checkif(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] Quote Link to comment 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.