Jump to content

Mysql_query("DELETE FROM users WHERE id=$row['id']") WHATS WRONG?!


Ptsface12

Recommended Posts

Hello,

Could you please help me? I have an ID and I want to delete a user dependant on there ID. The ID is in the URL.

 

Here's my php

<?php

if (isset($_GET['action']) && $_GET['action'] === 'delete')
{
if ((isset($_GET['action']))&&($_GET['action'] == 'edit')) {
         $user_id = (int) $_GET['user_id'];
include 'config.php';
mysql_connect(localhost,$username, $password);
@mysql_select_db($database) or die ("Unable to select Database");
$result = mysql_query("DELETE FROM users WHERE id=$row['id']");
$row = mysql_fetch_assoc($result);
$returnvalue=$row['username'];
}
}


?>

 

But I get an error on line 69 (

DELETE FROM users WHERE id=$row['id']
)

 

What's wrong with that sql?

 

Best Wishes,

Ptsface12

Link to comment
Share on other sites

Should be

 

$result = mysql_query("DELETE FROM users WHERE id=$user_id");

 

You got some serious flaws in understanding the logic. Your are just asking questions on different threads and combining the code from different answers without taking the effort to really understand whats happening. No offence but thats how I see it. You actually have to TRY and understand why things are done like they are and not just copy pasting and failing and asking again and copy pasting again and failing ain't gonna take you nowhere.

 

 

Plus this does absolutely nothing after the delete query

$row = mysql_fetch_assoc($result);
$returnvalue=$row['username'];

 

If you want to see how many rows were affected by your delete query you need to use mysql_num_rows(). You don't fetch rows from DELETE query.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.