Hi,
I have a database with a table named "main" and 3 fields:
division
name
year
The php code below will delete from the mysql database forever unless you add it back in. Is there a way when I click on the delete button in the code below for it to just delete it temporarily or cancel it?
Lets say I delete on record today, and then I want to bring it back a week from now by making it live again and without any information lost by clicking on a form button or link.
Is something like this possible?
<?php
require('db.php');
@session_start();
$err_string = "";
$quotechar = "`";
$quotedate = "'";
$sql = "";
$sql_ext = "";
$fields = array();
$fields[0] = "main.division";
$fields[1] = "main.name";
$fields[2] = "main.year";
$fields = array();
$fields[0] = "main.division";
$fields[1] = "main.name";
$fields[2] = "main.year";
$fieldcons = array();
$fieldcons[0] = "main.`division`";
$fieldcons[1] = "main.`name`";
$fieldcons[2] = "main.`year`";
$sql .= " Select\n";
$sql .= " main.`division`,\n";
$sql .= " main.`name`,\n";
$sql .= " main.`year`,\n";
$sql .= " From\n";
$sql .= " main main\n";
if (strpos(strtoupper($sql), " WHERE ")) {
$sqltemp = $sql . " AND (1=0) ";
}else{
$sqltemp = $sql . " Where (1=0) ";
}
$result = mysql_query($sqltemp . " " . $sql_ext . " limit 0,1")
or die("Invalid query");
$qry_string = "";
$value_sql = "";
$currentrow_sql = "";
$hidden_tag = "";
$hiddenrow_tag = "";
$i = 0;
while ($i < mysql_num_fields($result))
{
$meta = mysql_fetch_field($result)
;
$field_name = $meta->name;
$field_type = $meta->type;
$type_field = "";
$type_field = returntype($field_type);
$quotedata = "";
switch ($type_field) {
case "type_datetime": $quotedata = $quotedate; break;
case "type_string": $quotedata = "'"; break;
case "type_integer": $quotedata = ""; break;
case "type_unknown": $quotedata = "'"; break;
default: $quotedata = "'";
}
if (qsrequest("currentrow_fd"
.$i) != "") {
if ($currentrow_sql == "") {
$currentrow_sql = $fields[$i] . " = " . $quotedata . qsrequest("currentrow_fd" . $i) . $quotedata . "";
} else {
$currentrow_sql .= " and " . $fields[$i] . " = " . $quotedata . qsrequest("currentrow_fd" . $i) . $quotedata . "";
}
$hiddenrow_tag .= "<input type=\"hidden\" name=\"currentrow_fd" . $i . "\" value=\"" . qsrequest("currentrow_fd" . $i) . "\">\n";
}
$i++;
}
if (isset($_POST["act"])) {
$sql = "";
$sql = "delete from " . $quotechar. mysql_field_table($result,
0) . $quotechar;
$sql .= " where ";
$sql .= qsreplace_backslashes(stri
pslashes($
currentrow
_sql));
////url for submission page///
$submiturl = "main.php?";
if ($result > 0) {mysql_free_result($result
);}
if ($err_string == "") {
if (!$result = @mysql_query($sql)){
$err_string .= "<strong>Error:</strong>wh
ile updating<br>" . mysql_error();
}
if ($err_string == "") {
if ($qry_string != "") {
$URL= $submiturl . "&" . $qry_string;
} else {
$URL= $submiturl;
}
header ("Location: $URL");
exit;
}
}
}
else {
if ($result > 0) {mysql_free_result($result
);}
$sql = "";
$sql .= " Select\n";
$sql .= " main.`division`,\n";
$sql .= " main.`name`,\n";
$sql .= " main.`year`,\n";
$sql .= " From\n";
$sql .= " main main\n";
if ($currentrow_sql != "") {
$sql .= " where ".$currentrow_sql ;
}
$result = mysql_query($sql) or die("Invalid query");
$row = mysql_fetch_array($result)
;
}
?>
<html>
<head>
<title>-</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<h1>Cancel</h1>
<form name="delete" method="post" action="division_delete.ph
p">
<?php
print $hidden_tag;
print $hiddenrow_tag;
?>
<table border="0" cellpadding="2" cellspacing="1" bgcolor="#fff">
<?php
$css_class = "\"alt\"";
?>
<tr>
<td colspan="2" class="row">Cancel</td>
</tr>
<tr>
<td class="row">Division</td>
<?php
$itemvalue = "" . $row[0] . "";
if ($itemvalue == "") {
$itemvalue = " ";
}
$cellvalue = $itemvalue;
if ($cellvalue == "") {
$cellvalue = " ";
}
print "<td class=" . $css_class . " align=Default >" . $cellvalue . "</td>";
?>
</tr>
<tr>
<td class="row">Name</td>
<?php
$itemvalue = "" . $row[1] . "";
if ($itemvalue == "") {
$itemvalue = " ";
}
$cellvalue = $itemvalue;
if ($cellvalue == "") {
$cellvalue = " ";
}
print "<td class=" . $css_class . " align=Default >" . $cellvalue . "</td>";
?>
</tr>
<tr>
<td class="row">Year</td>
<?php
$itemvalue = "" . $row[2] . "";
if ($itemvalue == "") {
$itemvalue = " ";
}
$cellvalue = $itemvalue;
if ($cellvalue == "") {
$cellvalue = " ";
}
print "<td class=" . $css_class . " align=Default >" . $cellvalue . "</td>";
?>
</tr>
<tr>
<td class="row"> </td>
<td class="alt" align="default">
<input type="submit" name="sumit" value="Delete">
</td>
</tr>
</table><br />
</form>
<?php
if ($result > 0) {mysql_free_result($result
);}
if ($link > 0) {mysql_close($link);}
?>
</body>
</html>