Jump to content

Delete MySQL data with a link?


toxic27
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...