...

View Full Version : can someone help me,plezz,urgent



zura
05-21-2008, 06:43 AM
how i want to make delete script using php? i had tried many code but it didn't work... i maked checked box for deletion and when user click delete button then appear alertbox.. if they click "ok" the row that i want to delete will be delete and when they click"cancel" , it will remain the same table.. plezz check of my code.. i'm new in php..


<?php require_once('Connections/mas.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);

$logoutGoTo = "login.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;

// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}

$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}

mysql_select_db($database_mas, $mas);
$query_reg = "SELECT * FROM medic_block_reg";
$reg = mysql_query($query_reg, $mas) or die(mysql_error());
$row_reg = mysql_fetch_assoc($reg);
$totalRows_reg = mysql_num_rows($reg);

mysql_select_db($database_mas, $mas);
$query_name = "SELECT * FROM medic_student";
$name = mysql_query($query_name, $mas) or die(mysql_error());
$row_name = mysql_fetch_assoc($name);
$totalRows_name = mysql_num_rows($name);
?>







<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>View Record | Medic Assessment System</title>
<style type="text/css">
<!--
.style1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
.style2 {color: #FFFFFF}
.style3 {color: #333333; }
.style4 {color: #000000}
.style6 {font-size: 14; }
-->
</style>
<script type="text/JavaScript">
<!--
function MM_popupMsg(msg) { //v1.0
alert(msg);
}
//-->
</script>
</head>

<body>
<form action="" method="post" name="form1" class="style1" id="form1">
<table width="763" height="24" border="0" align="center">
<tr>
<td bgcolor="#FFFFFF"><p align="center">&nbsp;</p>
<p align="center" class="style3"><strong>List of Registered Student</strong></p>
<table width="662" height="74" border="1" align="center" bordercolor="#99CC00">
<tr>
<td width="88" height="38" bgcolor="#FFFFCC" class="style3"><div align="center" class="style6">Matric No. </div></td>
<td width="140" bgcolor="#FFFFCC" class="style3"><div align="center" class="style6">Name</div></td>
<td width="60" bgcolor="#FFFFCC" class="style3"><div align="center" class="style6">Sessi</div></td>
<td width="53" bgcolor="#FFFFCC" class="style3"><div align="center" class="style6">Year</div></td>
<td width="59" bgcolor="#FFFFCC" class="style3"><div align="center" class="style6">Block</div></td>
<td width="62" bgcolor="#FFFFCC" class="style3"><div align="center" class="style6">Group</div></td>
<td width="64" bgcolor="#FFFFCC" class="style3"><div align="center" class="style6">Status</div></td>
<td width="84" bgcolor="#FFFFCC" class="style3"><div align="center">Delete</div></td>
</tr>
<?php do { ?>
<tr>
<td bgcolor="#CCFFCC" class="style3"><div align="center"> <?php echo $row_reg['matric_no']; ?> </div></td>
<td bgcolor="#CCFFCC" class="style3"><div align="center"><?php echo $row_reg['name']; ?></div></td>
<td bgcolor="#CCFFCC" class="style3"><div align="center"><?php echo $row_reg['sessi']; ?></div></td>
<td bgcolor="#CCFFCC" class="style3"><div align="center"><?php echo $row_reg['year']; ?></div></td>
<td bgcolor="#CCFFCC" class="style3"><div align="center"><?php echo $row_reg['block']; ?></div></td>
<td bgcolor="#CCFFCC" class="style3"><div align="center"><?php echo $row_reg['group']; ?></div></td>
<td bgcolor="#CCFFCC" class="style3"><div align="center"><?php echo $row_reg['status']; ?></div></td>
<td bgcolor="#CCFFCC" class="style3"><div align="center">
<label></label>
<label>
<input type="checkbox" name="checkbox" id="checkbox" value="<?php echo $row_reg['matric_no']; ?>"
<?php echo $row_reg['name']; ?>
<?php echo $row_reg['sessi']; ?>
<?php echo $row_reg['year']; ?>
<?php echo $row_reg['block']; ?>
<?php echo $row_reg['group']; ?>
<?php echo $row_reg['status']; ?>/>

</label>
</label>
</div></td>
</tr>
<?php } while ($row_reg = mysql_fetch_assoc($reg)); ?>
</table>
<p align="center"><span class="style2"><span class="style4"> <a href="reg_query.php">Back</a> | <a href="main.php">Module Menu</a> | </span></span><span class="style2"><a href="<?php echo $logoutAction ?>" onclick="MM_popupMsg('You\'re successfully logout from this system...')">Logout</a></span>
<input name="Submit" type="submit" class="style4" id="button" value="DELETE"
onclick="window.confirm('Are You Really Sure?')"/>


</p>
<p align="center">&nbsp;</p></td>
</tr>
</table>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p>&nbsp;</p>
</form>
<EMBED NAME='CS1210513108413' SRC='Windows Notify.wav' LOOP=false
AUTOSTART=false MASTERSOUND HIDDEN=true WIDTH=0 HEIGHT=0></EMBED>
</body>
</html>
<?php
mysql_free_result($reg);

mysql_free_result($name);
?>

FWDrew
05-21-2008, 07:00 AM
Hi,

I am sorry I cant help with most of your question, however, I believe you will need to use a "confirm box" instead of an alert box so you can evaluate whether or not their click evaluates to true of false and then procceed. Of course, I am not sure what you are going to do for that part of your script if they have javascript disabled...
Anyway, I think you need to use a confirm box :)

http://www.w3schools.com/js/js_popup.asp

Best of luck,

Drew



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum