Forum Moderators: coopster

Message Too Old, No Replies

Delete from db table not working.

very simple php which I have never done before.

         

dkin

1:20 am on Jul 23, 2004 (gmt 0)

10+ Year Member



I have this code.

<?php
if (!eregi("modules.php", $PHP_SELF)) {
die ("You can't access this file directly...");

}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
include("header.php");
$index = 0;
$member = $_POST[user];
$db = mysql_connect("localhost", "", "");
mysql_select_db("",$db);
$query = mysql_query("DELETE FROM nuke_guild_members WHERE member_name=$member",$db);
$result = mysql_query($query);
OpenTable();
echo "$member has been deleted.";
CloseTable();

include("footer.php");

?>

I assume everything in that code is fine, but I am a new php coder so I am hoping that a mod or php guru could find my problem.

It is returning the echo fine but the member is not being deleted from the database.

What am I doing wrong.

Also if I wanted to be able to edit the columns for a certain member how would I do that. I never have been able to get this stuff to work.

[edited by: jatar_k at 4:05 pm (utc) on July 23, 2004]
[edit reason] removed url [/edit]

Zipper

5:18 am on Jul 23, 2004 (gmt 0)

10+ Year Member



there seem to be a lot of unwanted code, but i'm not quite sure whether they are used else where. why don't you stick to the basics.

$member = $_POST['user'];
@mysql_connect("localhost","username","pw") or die("Can't Connect to server");
@mysql_select_db("wmville") or die ("Can't Connect to DB");

$query = "DELETE FROM nuke_guild_members WHERE member_name = '$member'";

$result = mysql_query($query) or die(mysql_error());

if($result){
echo "$member has been deleted.";
}

Also use the following sql query to edit table columns.


$sql = "UPDATE table_name SET column1 = value1, column2 = value2 WHERE member_name = '$member'";

One more thing, I'm assuming member_name to be a string (VARCHAR). If it is, then it's highly recommended to use member_id (INT), if you have one, to find members when querying the database.