can someone help me to check this...what did i do wrong
i add the ability to restore back the data in the 'recycle bin' (restore.php)
last time i didn't input/check it properly
the problem if i input first name,last name as text it is not inserted to the bin table...
but if i put first name,last name as numbers it is ok it is inserted to the bin table and i can restore it back to person table
and how do i put add new ability to delete in restore.php...
newbie here
please help...thanks
Person
http://img690.imageshack.us/i/person.jpg/
Bin
http://img215.imageshack.us/i/bint.jpg/
mylist.php
PHP Code:
<?php
include "connect.php";
$result = mysql_query("SELECT * FROM person");
echo '<form action="mydelete.php" method="post">';
echo '<table border="1">
<tr>
<th>ID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>';
$count = 1;
while($row = mysql_fetch_array($result))
{
$id=$row['id']; echo "<tr>";
echo "<td>";
echo $count++;
echo "<input type='checkbox' name='id[]' value='$id'></td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "</tr>";
}
echo '</table>
<br />
<input type="submit" value="Delete" />
</form>';
include "menu.php";
mysql_close($con);
?>
mydelete.php
PHP Code:
<?php
include "connect.php";
$id=$_POST[id];
for($i=0;$i<count($_POST['id']);$i++)
{
$result = mysql_query("SELECT * FROM person WHERE id={$id[$i]}") or die(mysql_error());
$row = mysql_fetch_array( $result ) or die(mysql_error());
mysql_query("INSERT INTO bin (id, firstname, lastname, age)
VALUES
(". $row['id'] . ",". $row['firstname'] . ",". $row['lastname'] . ",". $row['age'] . ")");
mysql_query("DELETE FROM person WHERE id={$id[$i]}");
}
echo "$i records deleted";
include "menu.php";
mysql_close($con);
?>
restore.php
PHP Code:
<?php
include "connect.php";
$result = mysql_query("SELECT * FROM bin");
echo '<form action="restore-success.php" method="post">';
echo "<H4>Deleted Items</H4>";
echo "Select To Restore";
echo '<table border="1">
<tr>
<th>No</th>
<th>Deleted ID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>';
$count = 1;
while($row = mysql_fetch_array($result))
{
$bin_id=$row['bin_id'];
echo "<tr>";
echo "<td>";
echo $count++;
echo "<input type='checkbox' name='bin_id[]' value='$bin_id'></td>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "</tr>";
}
echo '</table>
<br />
<input type="submit" value="Restore" />
</form>';
include "menu.php";
mysql_close($con);
?>
restore-success.php
PHP Code:
<?php
include "connect.php";
$bin_id=$_POST[bin_id];
for($i=0;$i<count($_POST['bin_id']);$i++)
{
$result = mysql_query("SELECT * FROM bin WHERE bin_id={$bin_id[$i]}") or die(mysql_error());
$row = mysql_fetch_array( $result ) or die(mysql_error());
mysql_query("INSERT INTO person (id, firstname, lastname, age)
VALUES
(". $row['id'] . ",". $row['firstname'] . ",". $row['lastname'] . ",". $row['age'] . ")");
mysql_query("DELETE FROM bin WHERE bin_id={$bin_id[$i]}");
}
echo "$i records restored";
include "menu.php";
mysql_close($con);
?>
Bookmarks