0

I want to delete some rows from my table. But when I click delete, this just show me a blank page. I'm sure about id value and my db connection.

This is my code:

// connect to the database
include('connect-db.php');

// confirm that the 'id' variable has been set
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
    // get the 'id' variable from the URL
    $id = $_GET['id'];

    // delete record from database
    if ($stmt = $mysqli->prepare("DELETE FROM my_table WHERE id = ? LIMIT 1")) {
        $stmt->bind_param("i",$id);
        $stmt->execute();
        $stmt->close();
    } else {
        echo "ERROR: could not prepare SQL statement.";
    }
    $mysqli->close();

    // redirect user after delete is successful
    header("Location: Dashboard.php");
} else {
    // if the 'id' variable isn't set, redirect the user
    header("Location: Dashboard.php");
}
peterh
  • 11,875
  • 18
  • 85
  • 108
Sajad Asadi
  • 97
  • 2
  • 14
  • Could you [turn on error reporting](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php) and see what errors you are getting? – Chris Apr 24 '16 at 11:21

2 Answers2

0

There is a similar question MySQLi Prepared Statement not executing . Basically, you can try running the SQL directly in the database to see if you get any errors. Also confirm that the database user has delete permissions and that the id is stored as an integer in your database.

Community
  • 1
  • 1
Love2Code
  • 179
  • 1
  • 10
  • i tested that mysqli query in phpmyadmin and code worked but still when i click on .../delete.php?id=? link it returns me nothing and goiing blank – Sajad Asadi Apr 25 '16 at 13:13
-1

First I'd suggest you use the $_POST method, you can read more about it GET vs. POST.

Try using bindValue() instead of bindParam(), I believe something else needs to be declared for bindParam() I forget (I'm new at PHP too).

Community
  • 1
  • 1