Hi All
I am trying to create a page to delete records from a database, but i cannot seem to get the right code in
hereunder please find my code
<?php require_once('Connections/conn.php'); ?>
<?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;
}
}
if ((isset($_GET['productID'])) && ($_GET['productID'] != "")) {
$deleteSQL = sprintf("DELETE FROM Products WHERE productCode=%s",
GetSQLValueString($_GET['productID'], "text"));
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($deleteSQL, $conn) or die(mysql_error());
}
mysql_select_db($database_conn, $conn);
$query_delete = "SELECT productID, productCode, productName, productDesc, productPrice FROM tblproducts ORDER BY productID ASC";
$delete = mysql_query($query_delete, $conn) or die(mysql_error());
$row_delete = mysql_fetch_assoc($delete);
$totalRows_delete = mysql_num_rows($delete);
?><!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=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
Product ID <?php echo $row_delete['productID']; ?> Product Code<?php echo $row_delete['productCode']; ?>
<label></label>
Product Name<?php echo $row_delete['productName']; ?>
<input name="hiddenField" type="hidden" id="hiddenField" value="<?php echo $row_delete['productID']; ?>" />
<input type="submit" name="delete" id="delete" value="Submit" />
</form>
product
</body>
</html>
<?php
mysql_free_result($delete);
?>