Jump to content

Delete MySQL data with a link?


toxic27

Recommended Posts

As I suspected, the literal value: " $id " is being used as the search key for the delete function.Can you post the section of the script which handles the echoing of the 'delete' link? and the DB Query it uses, please.this is getting very close to completion. Just needs a minor adjustment to pick up the correct id value.

Link to comment
Share on other sites

echo '</tr><tr>';if($session->isAdmin()){echo '<td align="left" style="text-indent: 14pt" colspan="2"><h5> '.stripslashes($info2->comment).'<br><a href="delete_comment.php?comment_id=$id">DELETE</a></h5><br></td>';}else{echo '<td align="left" style="text-indent: 14pt" colspan="2"><h5> '.stripslashes($info2->comment).'</h5><br></td>';}echo '</tr><tr>';

And what do you mean about the Database Query? MyPHPAdmin stuff?

Link to comment
Share on other sites

Oh ok, this right?

//query comments for this page of this article$inf = "SELECT * FROM `comments` WHERE page = '".stripslashes($_SERVER['REQUEST_URI'])."' ORDER BY time ASC";$info = mysql_query($inf);if(!$info) die(mysql_error());

Link to comment
Share on other sites

//query comments for this page of this article$inf = "SELECT * FROM `comments` WHERE page = '".stripslashes($_SERVER['REQUEST_URI'])."' ORDER BY time ASC";$info = mysql_query($inf);if(!$info) die(mysql_error());$req_user_info = $database->getUserInfo($req_user);$info_rows = mysql_num_rows($info);if($info_rows > 0) {echo '<table width="400pt">';while($info2 = mysql_fetch_object($info)) { echo '<tr>'; if($session->logged_in){echo '<td><div style="color: lightslategray" align="left"><br><h5>Comment by '.$req_user_info['username'].' on '.$info2->date.'</h5></b></div></td>';}else{echo '<td><div style="color: lightslategray" align="left"><br><h5>Comment by '.$req_user_info['username'].' on '.$info2->date.'</h5></b></div></td>';}echo '</tr><tr>';if($session->isAdmin()){echo '<td align="left" style="text-indent: 14pt" colspan="2"><h5> '.stripslashes($info2->comment).'<br><a href="delete_comment.php?comment_id=$id">DELETE</a></h5><br></td>';}else{echo '<td align="left" style="text-indent: 14pt" colspan="2"><h5> '.stripslashes($info2->comment).'</h5><br></td>';

Here you go

Link to comment
Share on other sites

I am not familiar with OOPS style code. More a procedural guy, myself, but try this:

if($session->isAdmin()){$id = $info2->id;echo '<td align="left" style="text-indent: 14pt" colspan="2"><h5> '.stripslashes($info2->comment).'<br><a href="delete_comment.php?comment_id=$id">DELETE</a></h5><br></td>';}

Link to comment
Share on other sites

Okay, wait for someone who knows OOPS to come along and figure out the correct code to add the id number into the delete link.Sorry that I am unable to finish this one for you.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...