DrevanTonder
DrevanTonder

Reputation: 727

php delete record using id

This program is meant to delete a record when given the id.

php:

if ($_GET['type']=="file"){

    $servername = "localhost";
    $username = "****";
    $password = "****";
    $dbname = "****";

    // Create connection
    $conn = mysqli_connect($servername, $username, $password, $dbname);
    // Check connection
    if (mysqli_connect_error($conn)) {
        die("Connection failed: " . mysqli_connect_error($conn));
    }
    $sql = "SELECT id,user, FROM CreationsAndFiles WHERE id =".$_GET['id']." LIMIT 1";
    $result = mysqli_query($conn,$sql);
    $row = mysqli_fetch_assoc($result);
    if ($row['user'] == $login_session){
        $sql = "DELETE FROM CreationsAndFiles WHERE id=".$_GET['id'];
        if(mysqli_query($conn, $sql)){echo "deleted";}
    }
    mysqli_close($conn);
    //header("location: index.php?page=CreationsAndFiles");
}

the header is type=file&id=9 there is a record where id=9 It for no apparent reason will not work.

Upvotes: 0

Views: 574

Answers (1)

Joachim Isaksson
Joachim Isaksson

Reputation: 180917

Your SQL syntax is wrong;

SELECT id,user, FROM CreationsAndFiles...
              ^ extra comma

should be simply

SELECT id,user FROM CreationsAndFiles...

You may want to sanitize your input though, for example simply entering type=file&id=id will most likely do bad things.

Upvotes: 2

Related Questions