hi..i'm a php/mysql newbie
i would like my script to be when i delete a record i want all the record to be put into a new table called bin
i tried this but it didn't work
delete.phpPHP Code:<?php
include "connect.php";
$result = mysql_query("SELECT * FROM person");
echo "<form action='delete.php' method='post'>";
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>";
while($row = mysql_fetch_array($result))
{
$id=$row['id']; echo "<tr>";
echo "<td>" . $row['id'] . " <input type='radio' 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);
?>
PHP Code:<?php
include "connect.php";
$id=$_POST[id];
//$id = intval($_POST['id']);
mysql_query("DELETE FROM person WHERE id=$id");
mysql_query("INSERT INTO bin (id, firstname, lastname, age)
VALUES
('$_POST[id]','$_POST[firstname]','$_POST[lastname]','$_POST[age]') WHERE id=$id");
printf("Records deleted: %d\n", mysql_affected_rows());
include "menu.php";
mysql_close($con);
?>help ...thank you in advance--
-- Table structure for table `bin`
--
CREATE TABLE IF NOT EXISTS `bin` (
`bin_id` int(3) NOT NULL auto_increment,
`id` int(3) NOT NULL,
`firstname` varchar(15) collate latin1_general_ci NOT NULL,
`lastname` varchar(15) collate latin1_general_ci NOT NULL,
`age` int(3) NOT NULL,
PRIMARY KEY (`bin_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
--
-- Table structure for table `person`
--
CREATE TABLE IF NOT EXISTS `person` (
`id` int(3) NOT NULL auto_increment,
`firstname` varchar(15) collate latin1_general_ci NOT NULL,
`lastname` varchar(15) collate latin1_general_ci NOT NULL,
`age` int(3) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;![]()




Reply With Quote

Bookmarks