-1

Okay, so the problem is, I can't delete any comment.. I've been watching some guides but couldn't find much help, here's the code;

<?php
include "core/inc/conn.php";

mysql_select_db("comments");

$getquery = mysql_query("SELECT * FROM comments ORDER BY id DESC");
while($rows = mysql_fetch_assoc($getquery))
 {
     $id = $rows['id'];
     $comment_name = $rows['name'];
     $comment = $rows['comment'];
     $dellink = "<a href=\delete.php?id=' . $id . \'> Delete </a>";


     echo"<tr><th>$id</th>";
     echo"<th><form action='checked.php' method='checked'></th>";
     echo "<th>$comment_name</th>";
     echo"<th>$comment</th>";
     echo"<th>$dellink</th>";
    echo"<th>$ipserver</th></tr>";


 }

    if(isset($_GET['error']))
{
    echo "<p>15 Bokstäver max!";

}


?>

The $dellink isn't working, here's the delete.php;

<?php
include "core/inc/conn.php";

mysql_select_db('comments');


$deleteid = $_GET['id'];
mysql_query("DELETE FROM comments WHERE id='$deleteid'");
header("location: administrative/logs.php");

?>
  • 1
    **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Apr 01 '14 at 10:35
  • What happens when you click on the delete link? What URL does the browser go to? Is that the URL you expect? – Quentin Apr 01 '14 at 10:36
  • I'm making a simple website for my teacher, and we're just going to use it in some classes, I'm pretty sure they won't harm the database, though, I'm new to coding and I really have no clue what you just told me, sorry but thanks! :) – user3413045 Apr 01 '14 at 10:37
  • Everything's right with the URL, though, the id is wrong, instead of showing me the ID of the comment it says, /delete.php?id=%27 on every single comment.. :/ – user3413045 Apr 01 '14 at 10:38
  • So, the URL isn't right because it has `%27` instead of the value you were expecting. Look at the HTML you are generating, is it what you expect? – Quentin Apr 01 '14 at 10:40
  • @user3413045 - Have you tried my [answer](http://stackoverflow.com/a/22783366/696364) ? – Rikesh Apr 01 '14 at 10:40
  • @Rikesh, Yes I have, it didn't work, but I'll look at the other things you recommended, thanks! :) – user3413045 Apr 01 '14 at 10:43
  • @user3413045 - Can you define exactly what dose *not work* ? What is happening exactly ? – Rikesh Apr 01 '14 at 10:44
  • @Rikesh, well it just shows me; mywebsite.me/administrative/delete?id=%27 on every comment, which means somehow, it can't find the ID.. but, the logs.php can find the ID from MySQL database, but I just can't get it to work by deleting it! :( – user3413045 Apr 01 '14 at 10:48
  • Have you exactly post the link I provide you ? Can you post your updated line ? – Rikesh Apr 01 '14 at 10:49
  • 1
    Oh finally! Your thing worked, but I tried it before and it didn't show any results, though it works perfectly now! Thanks everyone for replying! :) Thanks @Rikesh ;) – user3413045 Apr 01 '14 at 10:52

1 Answers1

0

The PHP echoing your deletion link isn't quite right, try:

$dellink = '<a href="delete.php?id=' . $id . '> Delete </a>';

*[obligatory don't use mysql_ functions text]*

martincarlin87
  • 10,848
  • 24
  • 98
  • 145