Hi,
I'm having trouble writing the code for deleting a row with a checkbox.
My page allready contains an update and a insert form, which works great, but removing rows with a checkbox stills a pain in the ass.
This is my php code. I really don't know what I have to put in place of ?????????, or what I specifically have to do, am I doing something wrong ?
Thanks in advance !!!
<?php require_once('../../Connections/fisherintranet.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;
}
$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO licenties (company, license) VALUES (%s, %s)",
GetSQLValueString($HTTP_POST_VARS['company'], "text"),
GetSQLValueString($HTTP_POST_VARS['license'], "text"));
mysql_select_db($database_fisherintranet, $fisherintranet);
$Result1 = mysql_query($insertSQL, $fisherintranet) or die(mysql_error());
}
if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "form3")) {
$updateSQL = sprintf("UPDATE licenties SET company=%s, license=%s WHERE license=%s",
GetSQLValueString($HTTP_POST_VARS['company'], "text"),
GetSQLValueString($HTTP_POST_VARS['licupdate'], "text"),
GetSQLValueString($HTTP_POST_VARS['license'], "text"));
mysql_select_db($database_fisherintranet, $fisherintranet);
$Result1 = mysql_query($updateSQL, $fisherintranet) or die(mysql_error());
$updateGoTo = "licenties.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
if ((isset($HTTP_POST_VARS["MM_remove"])) && ($HTTP_POST_VARS["MM_remove"] == "form2")) {
$removeSQL = sprintf("Delete from licenties WHERE 'ID'==???????????");
mysql_select_db($database_fisherintranet, $fisherintranet);
$Result1 = mysql_query($removeSQL, $fisherintranet) or die(mysql_error());
$removeGoTo = "licenties.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$removeGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$removeGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $removeGoTo));
}
session_start();
if ($HTTP_SESSION_VARS["statusCheck"] != "Admin")
header("Location: menu.php");
$colname_licenties = "1";
if (isset($HTTP_SESSION_VARS['companyCheck'])) {
$colname_licenties = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['companyCheck'] : addslashes($HTTP_SESSION_VARS['companyCheck']);
}
mysql_select_db($database_fisherintranet, $fisherintranet);
$query_licenties = sprintf("SELECT license FROM licenties WHERE company = '%s' ORDER BY license ASC", $colname_licenties);
$licenties = mysql_query($query_licenties, $fisherintranet) or die(mysql_error());
$row_licenties = mysql_fetch_assoc($licenties);
$totalRows_licenties = mysql_num_rows($licenties);
$colname_alles = "1";
if (isset($HTTP_SESSION_VARS['companyCheck'])) {
$colname_alles = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['companyCheck'] : addslashes($HTTP_SESSION_VARS['companyCheck']);
}
mysql_select_db($database_fisherintranet, $fisherintranet);
$query_alles = sprintf("SELECT * FROM licenties WHERE company = '%s' ORDER BY license ASC", $colname_alles);
$alles = mysql_query($query_alles, $fisherintranet) or die(mysql_error());
$row_alles = mysql_fetch_assoc($alles);
$totalRows_alles = mysql_num_rows($alles);
?>
This is my code of my form :
<form name="form2" method="post" action="<?php echo $editFormAction; ?>">
<table width="30%" border="1" align="center" cellpadding="0" cellspacing="0" bgcolor="#999966">
<tr>
<td colspan="2" bgcolor="#999900"><div align="center"> <font color="#FFFFFF" face="Times New Roman, Times, serif"><strong>licenses</strong></font></div></td>
</tr>
<?php do { ?>
<tr>
<td><div align="center">
<p>
<input name="<?php echo $row_alles['ID']; ?>" type="checkbox" id="<?php echo $row_alles['ID']; ?>" value="<?php echo $row_alles['ID']; ?>">
<font color="#FFFFFF"> </font></p>
</div></td>
<td><div align="center">
<p><font color="#FFFFFF"><?php echo $row_licenties['license']; ?></font></p>
</div></td>
</tr>
<?php } while ($row_licenties = mysql_fetch_assoc($licenties)); ?>
</table>
<p align="center">
<input name="MM_remove" type="hidden" id="MM_remove" value="form1">
<input type="submit" name="Submit" value="Remove selected license">
</p>
</form>