Ptsface12 Posted July 19, 2011 Share Posted July 19, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/242307-mysql_querydelete-from-users-where-idrowid-whats-wrong/ Share on other sites More sharing options...
harristweed Posted July 19, 2011 Share Posted July 19, 2011 change $result = mysql_query("DELETE FROM users WHERE id=$row['id']"); to $result = mysql_query("DELETE FROM users WHERE id={$row['id']}"); Quote Link to comment https://forums.phpfreaks.com/topic/242307-mysql_querydelete-from-users-where-idrowid-whats-wrong/#findComment-1244490 Share on other sites More sharing options...
TeNDoLLA Posted July 19, 2011 Share Posted July 19, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/242307-mysql_querydelete-from-users-where-idrowid-whats-wrong/#findComment-1244500 Share on other sites More sharing options...
Ptsface12 Posted July 19, 2011 Author Share Posted July 19, 2011 Hello, And I know. I'm 13, I'm trying to understand all this, I've been writing alot of this code, hence why its gone wrong. All I'm trying to do is make a control panel, I mean god man sorry if I can't quite get it right. Quote Link to comment https://forums.phpfreaks.com/topic/242307-mysql_querydelete-from-users-where-idrowid-whats-wrong/#findComment-1244528 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.