ive just followed a tutorial where if a user chooses to delete there account and after i click delete account i get the following message Unable to delete user account!

can someone check this out for me please

delete.php

<?php
include ('dbconnect.php');

if (isset($_GET['del'])) {
    $user_id = $_GET['del'];

    $delete = "DELETE FROM `users` WHERE `user_id`='$user_id'";

    $res = mysqli_query($MySQLi_CON,$delete) or die('Unable to delete user account!');
    header('Location:index.php');
}

?>

Link to delete.php

<a href="delete.php?del=$row['user_id']">Delete Account</a>

and heres database table

CREATE TABLE IF NOT EXISTS `users` (
  `user_id` int(5) NOT NULL,
  `user_name` varchar(25) NOT NULL,
  `user_email` varchar(35) NOT NULL,
  `user_pass` varchar(255) NOT NULL
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

any help would be much appreicated x

Hi, at line 9 do:

 mysqli_query($MySQLi_CON, $delete) or die(mysqli_error($MySQLi_CON));

You should get the error returned from the database server.

hi im getting the following error after putting it on
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'user_id']'' at line 1

So how does look the real query? The one posted in your previous post does not match, it seems you are using:

$delete = "DELETE FROM `users` WHERE `user_id`='$_GET['user_id']'";

And it happens because you're using single quotes, in this case you should do:

`user_id`='$_GET[user_id]'

Or:

`user_id`='{$_GET['user_id']}'

But, why you do not use a prepared statement? It's very simple and puts your query in safe.

ive tried both of below but neither are working
this is the original from the tutorial that i followed online

<?php
include ('dbconnect.php');

if (isset($_GET['del'])) {
    $user_id = $_GET['del'];

    $delete = "DELETE FROM `users` WHERE `user_id`='$user_id'";

    $res = mysqli_query($MySQLi_CON,$delete) or die('Unable to delete user account!');
    header('Location:index.php');
}

?>

ive tried the following:
From

$delete = "DELETE FROM `users` WHERE `user_id`='$user_id'";

To

$delete = "DELETE FROM `users` WHERE `user_id`='$_GET[user_id]'

this didnt delete account so i tried
From

$delete = "DELETE FROM `users` WHERE `user_id`='$user_id'";

To

$delete = "DELETE FROM `users` WHERE     `user_id`='{$_GET['user_id']}'";

and that didnt work either althought there are no errors coming up from error message that i have added

$res = mysqli_query($MySQLi_CON, $delete) or die(mysqli_error($MySQLi_CON));

ive checked the database name and column name to check all matching and all is ok there

this is what im getting
DELETE FROM users WHERE user_id=''
Warning: Cannot modify header information - headers already sent by (output started at /home/jktempla/public_html/deleteaccount/delete.php:9) in /home/jktempla/public_html/deleteaccount/delete.php on line 11

Member Avatar for diafol

The problem is that you are printing output to the screen (echo $delete;) and then thinking you can redirect. Well you can't. If you could, then you wouldn't see the message. So while you have output to screen, you cannot redirect (header()).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.