| cowhoy 2006-02-25, 10:14 pm |
| I am trying to delete single user from the system according to his userID, but
when i try to delete one user, all users of same user type (e.g. student) will
be deleted at the same time, why? I am using DW MX2004 pro to build PHP dymanic
web pages.
<?php require_once('Connections/db.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "",
$theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" :
"NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
if ((isset($_GET['UserID'])) && ($_GET['UserID'] != "") &&
(isset($_POST['check']))) {
$deleteSQL = sprintf("DELETE FROM user WHERE UserID=%s",
GetSQLValueString($_GET['UserID'], "int"));
mysql_select_db($database_db, $db);
$Result1 = mysql_query($deleteSQL, $db) or die(mysql_error());
$deleteGoTo = "select-delete-user.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));
}
if ((isset($_GET['StudentID'])) && ($_GET['StudentID'] != "") &&
(isset($_POST['check']))) {
$deleteSQL = sprintf("DELETE FROM student WHERE StudentID=%s",
GetSQLValueString($_GET['StudentID'], "int"));
mysql_select_db($database_db, $db);
$Result1 = mysql_query($deleteSQL, $db) or die(mysql_error());
$deleteGoTo = "select-delete-user.php";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));
}
$colname_user = "1";
if (isset($HTTP_GET_VARS['UserID'])) {
$colname_user = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['UserID'] :
addslashes($HTTP_GET_VARS['UserID']);
}
mysql_select_db($database_db, $db);
$query_user = sprintf("SELECT * FROM `user` WHERE UserID = '%s'",
$colname_user);
$user = mysql_query($query_user, $db) or die(mysql_error());
$row_user = mysql_fetch_assoc($user);
$totalRows_user = mysql_num_rows($user);
?>
|