-1

I have created a script that displays the content from my database.

A button is linked to delete.php, however the delete.php doesn't work.

<?php

   $connect = @mysql_connect('localhost','Jazzoet','XEpCnYrZXLDHvYy3');
   mysql_select_db('jazzoet_optredens');
   $query = "SELECT * FROM optredens"; 
   $result = mysql_query($query);
   while($row = mysql_fetch_array($result)){  
          echo '<ul><li>' . $row['Naam'] . '</li><li>'  . $row['Datum'] . '</li><li>' .  $row['Omschrijving'] . '</li><li><a href=delete.php?id='.$row['OptredenId'].' >Delete</a></li></ul>';
   }

   mysql_close();

?>

delete.php

<?php

    $connect = @mysql_connect('localhost','Jazzoet','XEpCnYrZXLDHvYy3');
    mysql_select_db('jazzoet_optredens');

    $query = "DELETE  FROM optredens WHERE OptredenId='$_GET[id]'"; 

 ?>
Ben
  • 8,894
  • 7
  • 44
  • 80
  • [**Please, don't use `mysql_*` functions in new code**](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://uk.php.net/manual/en/function.mysql-connect.php)? Learn about [*prepared statements*](https://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide which. – Ben May 31 '16 at 14:54
  • Be careful with GET calls that result in deletion. Sometimes robots follow links. – Progrock May 31 '16 at 15:38
  • So how do i do this in mysqli ? – StaphHammertime May 31 '16 at 15:45

1 Answers1

1

You are not running the query.

<?php

    $connect = @mysql_connect('localhost','Jazzoet','XEpCnYrZXLDHvYy3');
    mysql_select_db('jazzoet_optredens');

    $query = "DELETE  FROM optredens WHERE OptredenId='$_GET[id]'"; 
    mysql_query($query); 
?>

However, as always, I recommend you to use new tutorials and do not use mysql library. It's deprecated.

If you are new to PHP, I recommend you start reading this tutorial

Mojtaba
  • 4,852
  • 5
  • 21
  • 38
  • Thank you very much for the answer. I in the meanwhile realized that there is a difference between msql and mysqli, i had no idea, neither has my teacher apparently. – StaphHammertime May 31 '16 at 22:17
  • @StaphHammertime, No problem. Actually, it's too easy to learn. I updated my answer and you can start learning mysqli. It's not too different than mysql – Mojtaba Jun 01 '16 at 13:10