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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.