Current location: Hot Scripts Forums » Programming Languages » PHP » edit and delete data


edit and delete data

Reply
  #1 (permalink)  
Old 08-06-03, 04:52 PM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
Question edit and delete data

hi,

Im am almost done with my program and all i need to do and edit and delete and im done but i dont know how to do it. if someone could help me i would be done with my program and could get it up 4 beta testing.thx.
Reply With Quote
  #2 (permalink)  
Old 08-09-03, 01:33 PM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
ok im going to give more details to help this go quicker. now i know the command 4 it is calling the file to edit it and calling the file to delete it.plz answer this b/c this is all i have to do and im done.
Reply With Quote
  #3 (permalink)  
Old 08-18-03, 02:44 PM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
ok i figured out how to delete and i figured out how to edit.so i need no help.
Reply With Quote
  #4 (permalink)  
Old 09-10-03, 10:40 AM
JSCHLIPP JSCHLIPP is offline
New Member
 
Join Date: Sep 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Talking

Well could you tell me how to do this as i am at this point as well

Jschlipp@stonemtntoyota.com
Reply With Quote
  #5 (permalink)  
Old 10-09-03, 06:56 PM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Just joined this forum so maybe I'm too late to help you out here. Are you looking for a way to edit and delete fields or rows in a table?
Reply With Quote
  #6 (permalink)  
Old 10-09-03, 07:00 PM
darkcarnival's Avatar
darkcarnival darkcarnival is offline
PHP/MySQL coder
 
Join Date: Jun 2003
Posts: 939
Thanks: 0
Thanked 0 Times in 0 Posts
well i wanted to be able to edit rows in a mysql database. but i fugired it ouit by looking at some code.if someone needs this ill be hapy to show it to you.
Reply With Quote
  #7 (permalink)  
Old 10-10-03, 08:37 AM
JSCHLIPP JSCHLIPP is offline
New Member
 
Join Date: Sep 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by darkcarnival
well i wanted to be able to edit rows in a mysql database. but i fugired it ouit by looking at some code.if someone needs this ill be hapy to show it to you.
COULD YOU PLEASE SHOW THIS TO ME?
Reply With Quote
  #8 (permalink)  
Old 10-10-03, 08:43 AM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
OK, let me know exactly what you are needing, and needing to do.
Reply With Quote
  #9 (permalink)  
Old 10-10-03, 08:54 AM
JSCHLIPP JSCHLIPP is offline
New Member
 
Join Date: Sep 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by mdhall
OK, let me know exactly what you are needing, and needing to do.
EXACTLY WHAT DARKCARNIVAL WAS LOOKING TO DO, HAVE A LIST OF SAY CONTACTS IN MY MYSQL DATABASE DISPLAYED WITH AN EDIT AND DELETE BUTTON NEXT TO THEM I HAVE THE FORM FOR THE EDIT I JUST NEED THE FORM FOR DELETE AND KNOW HOW TO CALL THE RECORD FROM ONE PAGE TO THE NEXT FOR EDIT AS WELL AS DELETE
Reply With Quote
  #10 (permalink)  
Old 10-10-03, 09:23 AM
mdhall's Avatar
mdhall mdhall is offline
Aspiring Coder
 
Join Date: Oct 2003
Posts: 510
Thanks: 1
Thanked 1 Time in 1 Post
Well, to edit and delete, I use separate scripts than the display and insert scripts. I'll show the basics of them, and what you need to change in them to reflect your own db.

Make a simple html page, with a form pointed to update.php. I just put in the row id number. For example...
<form action=update.php method=post>
Id number
<input type=text name=idedit size=20>
<input type=submit value=submit>
You just have to know the row number of the entry you want to edit.

Make a page called update.php, using the same connection process at the beginning of the script as your insert script. This is the one I use, you'll have to change the $variables (fname, lname, etc) to match your own information fields, and the display areas....

php
Connection process
$query=("SELECT* FROM table_name WHERE id='$idedit'");

$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_close();

$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$fname=mysql_result($result,$i,"fname");
$lname=mysql_result($result,$i,"lname");
$dept=mysql_result($result,$i,"dept");
$email=mysql_result($result,$i,"email");
$phone=mysql_result($result,$i,"phone");


?>
//Displays what is in the row
<form action="updated.php">
<input type="hidden" name="ud_id" value="<? echo "$id"; ?>">
<font face=verdana, times size=2><b>

First Name:<br>
<input type="text" name="ud_fname" value="<? echo "$fname"?>"><br>
Last Name:<br>
<input type="text" name="ud_lname" value="<? echo "$lname"?>"><br>
Department/Position:<br>
<input type="text" name="ud_dept" value="<? echo "$dept"?>"><br>
Email:<br>
<input type="text" name="ud_email" value="<? echo "$email"?>"><br>
Phone:<br>
<input type="text" name="ud_phone" value="<? echo "$phone"?>"><br>
<input type="Submit" value="Update">
</form></td>

<?
++$i;
}
?>

As I said, you need to change some areas, but keep the same structure, its fairly easy to understand. Now create a page called updated.php. This is referenced above in the update script. The update.php script will find the information already in the row and displays it, the updated.php script makes the actual changes.

updated.php
php
connection process
$query=("UPDATE table_name SET fname='$ud_fname', lname='$ud_lname', dept='$ud_dept', email='$ud_email', phone='$ud_phone' WHERE id='$ud_id'");

mysql_query($query);
echo "Contact Info Updated";
mysql_close();
echo "<meta http-equiv=\"refresh\" content=\"0; url=edited.html\" />\n";
?>

Again, look at the query section, and make it match the fields that you have already in your row. Make sure that the ud_id is the same in update.php & updated.php. The section at the bottom is not necessary, its simply a redirecton, so that after updating I go to another page.

I'll put the delete script in the next post.
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


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