General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 23rd, 2003, 11:52 PM
nestorvaldez nestorvaldez is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 40 nestorvaldez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 21 sec
Reputation Power: 6
Problem to edit a record

I need somebody help me how to edit a record in PHP..
I have made this question in other time and with the answer I feel lost. but now I need to solve an urgent problem.

I have a form with two field : ID and NAME
and I save the information in a mysql DB, when I finish to fill and save all the record (like 15), I have a link to list all record showing the ID and the NAME. Until here I'm ok. But I found out, I have a record wrong and I need to edit this record to change it.

I want a link in the ID field in the list I made, to click it and put this information in a form to edit.
I don't know what code use to put the record in the form.
I know that I need to use the UPDATE command to update the information in mysql, I know that, But I don't know how to put the information in the form. I want to know if I need to create a different form to put the information to edit or I use the same where I type the information the fist time..

If some body could help with this sending me an example with all the process, I'll very quite. I have problem with this..

Thanks

Nestor Valdez
nestor@ecreativodigital.com

Reply With Quote
  #2  
Old April 24th, 2003, 12:36 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
do your query

PHP Code:
 $q mysql("SELECT * FROM ??? WHERE ID = '{$_GET['ID']}'");
$r mysql_fetch_array($q); 


Code:
<input type="text" name="???" value="<?php echo $r['field']; ?>" />
__________________
-- Jason

Reply With Quote
  #3  
Old April 24th, 2003, 02:28 AM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via ICQ to avit
Picking up from what Taelo wrote, when you get your form results back, instead of UPDATE, you could try REPLACE. That way you can use the same form.

With replace, if the record doesn't exist, it is created. If it exists, it is replaced.

Reply With Quote
  #4  
Old October 3rd, 2003, 10:31 PM
nestorvaldez nestorvaldez is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 40 nestorvaldez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 21 sec
Reputation Power: 6
I'm trying to edit a record.. this is my code, the file "registra.php" and "update.php"

REGISTRA.PHP
==========
<form name="form1" method="get" action="update.php">
<input name="cia" type="text" id="cia" value="<?php echo $r['cia']; ?>">
<input name="nombrecia" type="text" id="nombrecia" value="<?php echo $r['nombrecia']; ?>" >
<input name="lploto" type="text" id="lploto" value="<?php echo $r['lploto']; ?>">
<input name="Update" type="submit" id="update" value="Update">

......

UPDATE.PHP
=========
<?
.... connection...

$q = mysql("SELECT cia, nombrecia, lploto, FROM parametros WHERE cia= '{$_GET['cia']}'");
$r = mysql_fetch_array($q);
?>

I type the number of 'cia', it is 1 and click UPDATE.. AND...
it return me this error..

Warning: Wrong parameter count for mysql() in /home/mailcrea/public_html/loto/update.php on line 22

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mailcrea/public_html/loto/update.php on line 23

what happen with my code.. I just want to edit or update this record.. only typing the number of it and when I click update it put all the data and field in each field of the form....

Reply With Quote
  #5  
Old October 3rd, 2003, 11:31 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
oops,...my fault

change "mysql" to mysql_query

lol

Reply With Quote
  #6  
Old October 3rd, 2003, 11:38 PM
nestorvaldez nestorvaldez is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 40 nestorvaldez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 21 sec
Reputation Power: 6
thanks...
I haven't get update a record.. I have a lot time trying it.

Ok.. not error, but when I submit. it go to the update.php. and it is blank...
in the form i have :
<form name="form1" method="get" action="update.php">

so it go to update.php... and it only have the code.. it must return to the form page with the data i'm retreiving..
what's wrong...

I want to do this by first time, update a record.....

what happen here.. Help me.... please..... I showed you the two files... REGISTRA.PHP and UPDATE.PHP

TELL ME WHAT I MUST DO..

Reply With Quote
  #7  
Old October 3rd, 2003, 11:45 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
on your update page, you will be using a form similar to the register page.

To fill the values in for editing, you need to echo the php variables back into an html form field.

Code:
<input type="text" name="firstName" value="<?php echo $result['firstName']; ?>">


see how this works?

Reply With Quote
  #8  
Old October 8th, 2003, 02:47 PM
nestorvaldez nestorvaldez is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 40 nestorvaldez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 21 sec
Reputation Power: 6
IĻm using 3 files to update...
the first with the form in blank, and when I submit I use the 2nd. then
the 2nd. Look for the record and put the data in the form, I make the modififcation in the 2nd form and submit it and I use the 3rd script to Update the record.

Iīm using this script to update a record in the 3rd script.....
It process ok, and donīt report any error, but when I check the record it is NOT modifyed.

$UpdRec = "UPDATE parametros SET cia='$cia', nombrecia='$nombrecia', lploto='$lploto', lplotopool5='$lplotopool5', lplotopool4='$lplotopool4', lppale12='$lppale12', lppale13='$lppale13', lppale23='$lppale23', lpquiniela1='$lpquiniela1', lpquiniela2='$lpquiniela2', lpquiniela3'$lpquiniela3', nppale12='$nppale12', nppale13='$nppale13', nppale23='$nppale23', npquiniela1='$npquiniela1', npquiniela2='$npquiniela2', npquiniela3='$npquiniela3' WHERE cia=1";
$r = mysql_query($UpdRec);

what must happen..

Reply With Quote
  #9  
Old October 8th, 2003, 11:33 PM
nestorvaldez nestorvaldez is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 40 nestorvaldez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 21 sec
Reputation Power: 6
I really need your help...

I have a report showing some information... and at the end of each record I have a checkbox..

I need that when I click a check box of a record, and I click the submit botton it update the table and Move a "S" to the column updated o f this record...

and I don't want it go to other page, I say that because when you put a script in the ACTION of the form it go to the page of this script.. I want it stay in the same page..

look at this... this is the page..I just want to move a "S" to the field called UPDATED when I select any record..
I don't know how to identify which record I'm selecting to move the "S"

http://www.mailcreativo.com/loto/jugadas.php

If it is possible....

Reply With Quote
  #10  
Old October 9th, 2003, 12:18 AM
nestorvaldez nestorvaldez is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 40 nestorvaldez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 21 sec
Reputation Power: 6
help please, I need to solve this problem..

I need to know How identify the record I checked.. to move the "S" in the UPDATED field in the table.

Reply With Quote
  #11  
Old October 10th, 2003, 11:34 PM
nestorvaldez nestorvaldez is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 40 nestorvaldez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 21 sec
Reputation Power: 6
Hi guys, I'm still without to solve my problem trying to edit a record...

In this script I'm inserting a record after that, I needed to update a record and then I show the record with a select.....

I need to know what happen, because it doesn't report me any error but it doesn't update the record.... I don't know how to do this, I still can update a record...

$query = "INSERT INTO jugada(cuenta, fecha, hora, categoria, lpale1, lpale2, lpalevalor, procesado) VALUES ('$CUENTA', NOW(), localtime(), 3, '$numero1', '$numero2', '$valor', 'N')";

mysql_query($query) or die (mysql_error());
$query = "SELECT * FROM cliente WHERE cuenta='$CUENTA'";

$UpdateRecords = "UPDATE cliente SET balance = balance - $valor WHERE cuenta='$CUENTA'";

$result = mysql_query("SELECT j.cuenta, j.fecha, j.hora, c.categoria, j.lpale1, j.lpale2, j.lpalevalor FROM jugada j, categoria c WHERE j.categoria = c.id AND j.cuenta=('$CUENTA') AND j.categoria=3 AND j.lpale1='$numero1' AND j.lpale2='$numero2' AND j.lpalevalor=$valor");

$row = mysql_fetch_array($result);


In other hand i posted a question about: how to edit a record where I'm using a select to show the information and at the end of each record I have a Checkbox and a submit button at the end of the report, and I want that when I check one or various record and click submit it save a "S" in one column of the record..
I need to now how Identify the record is check to be updated with the "S"..

All my problems are trying to edit a record...

Reply With Quote
  #12  
Old October 11th, 2003, 05:53 PM
nestorvaldez nestorvaldez is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 40 nestorvaldez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 21 sec
Reputation Power: 6
oh guys donīt you going to help me solve this problem.....

I really need it...

Reply With Quote
  #13  
Old October 11th, 2003, 08:59 PM
manoloweb manoloweb is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Monterrey MX
Posts: 49 manoloweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Hello Nestor,

It looks like you are having troubles understanding some basic concepts, because the answers posted before are good clues on how you should try to solve your problem...

You say that you know how to use an "UPDATE" sql instruction, well, that's the main issue here, so you are half the way already.

How to show the data so people can edit it?

Well, in order to do this, you should know which record is going to be edited, right? Then you go and make a select in your database, which gives you a $row with all the fields needed.

I can see you have this done too...

Now you only need to place every result field in the corresponding form field, like this:

PHP Code:
<input type="text" name ="cuenta" value ="<?= $row["cuenta"]?>"


And what about the "Select", "radio" and "chackbox" fields?

Well... is easy too.

You just need to evaluate if the db field equals the value of the current form field...

PHP Code:
<input type="checkbox" value="1" name="married"<? if ($row["married"]==1) { echo " checked"; } ?>


It all depends on how your form is created and used... There are a lot of techniques to achieve this goal, you just need to understand how it works.

Hope it helps

(I don't know if you speak spanish, but if you do so, feel free to PM me and I can clarify anything about this in spanish)

__________________
The deal is not to know everything, but to know the email of the one who does.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Problem to edit a record


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |