Current location: Hot Scripts Forums » Programming Languages » PHP » Help with 'recycle bin' code


Help with 'recycle bin' code

Reply
  #1 (permalink)  
Old 02-22-10, 06:43 PM
mulaus mulaus is offline
New Member
 
Join Date: Feb 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Help with 'recycle bin' code

Hi..

can someone help me to check this...what did i do wrong

i have this code add, edit, delete

i have two table , person (input data) and bin (deleted data)

i add the ability to restore back deleted data in the 'recycle bin' (restore.php)

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
Imageshack - person.jpg

Bin
Imageshack - 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);
?>

Last edited by mulaus; 02-22-10 at 06:48 PM.
Reply With Quote
  #2 (permalink)  
Old 02-22-10, 09:26 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Take out the periods, use {}

","{$row['firstname']}",".

Spend some time up at php.net, studying strings.
Reply With Quote
  #3 (permalink)  
Old 02-23-10, 04:58 AM
mulaus mulaus is offline
New Member
 
Join Date: Feb 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
i tried but not working
PHP Code:

"{$row['id']}","{$row['firstname']}","{$row['firstname']}","{$row['age']}
also tried below code but not working....this code is working perfectly if i input numbers for all fields i can delete and restore - but as text its failed to be inserted to bin table

PHP Code:

<?php

include "connect.php";



$id_array=$_POST[id];
foreach(
$id_array as $id)
{
$result mysql_query("SELECT * FROM person WHERE id=$id") or die(mysql_error());
while(
$row mysql_fetch_array($result))
{
$id=$row['id'];
$firstname=$row['firstname'];
$lastname=$row['lastname'];
$age=$row['age'];
}
echo 
$firstname;


mysql_query("INSERT INTO bin (id, firstname, lastname, age)
VALUES (
$id,$firstname,$lastname,$age)");

mysql_query("DELETE FROM person WHERE id=$id");

echo 
"Record deleted and inserted to recycle bin";

}

mysql_close($con);
?>

Last edited by mulaus; 02-23-10 at 05:07 AM.
Reply With Quote
  #4 (permalink)  
Old 02-24-10, 08:42 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Quote:
i tried but not working

PHP Code:
"{$row['id']}","{$row['firstname']}","{$row['firstname']}","{$row['age']}"
This isn't enough information for people to help you, and it isn't in the larger segment either. Please post the whole command, from start to semicolon, and all lines in between.
Reply With Quote
  #5 (permalink)  
Old 02-24-10, 04:33 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
Quote:
Originally Posted by wirehopper View Post
Take out the periods, use {}

","{$row['firstname']}",".

Spend some time up at php.net, studying strings.
Try: String starts with double-quote(").

PHP Code:



','{$row['firstname']}',' 
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Match code in link with code with one in file and extract line peuplarchie PHP 3 10-24-09 01:23 AM
Freeze columns in a table Rita Negi Script Requests 1 09-01-09 08:23 AM
OTO Redirect Code Placement Tony S. HTML/XHTML/XML 7 07-25-09 09:31 AM
Need captcha for html+php contact form sujata_ghosh PHP 6 03-22-09 03:46 PM
Explanation of Code... Please davidk19380 Perl 1 02-26-06 01:50 PM


All times are GMT -5. The time now is 08:11 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.