Connecting Tech Pros Worldwide Forums | Help | Site Map

Updating PHP Generated Form

onlymars's Avatar
Newbie
 
Join Date: Mar 2008
Posts: 13
#1: Mar 30 '08
Hi all fellows, i am in a messed up situation right now, i have a table in mysql containing different currencies and their values, i have generated a form in php which display them both, but now i want to update them. my mysql database has 2 fields 1. curr_name 2. curr_amount, i am reading both of them in a text box so that it can be updated, my php code here.. [php]echo "<table width='100%'>";
while($curr=mysql_fetch_array($result2))
{
$a=$curr['curr_name'];

echo "<tr><td>";

echo "<input name='" . $curr['curr_name'] . "' value='" . strtoupper($a) . "'>";

echo "<td><input name='" . $curr['curr_name'] . "' value='" . $curr['curr_amount'] . "'>";
echo "<td><a href='delete.php?currency=" . $curr['curr_name'] . "' >Delete Record</a>";

}
echo "</table>";[/php]as u would have noticed i am also deleting the record by sending information by GET method, which is working, but i need to update the values in the text fields.
this form has also function of inserting new records, so it has update, insert and delete opeartions. only update is messed up.
Plz help me out.

ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#2: Mar 30 '08

re: Updating PHP Generated Form


Welcome to The Scripts!

Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#3: Mar 30 '08

re: Updating PHP Generated Form


You only showed some form building code for the DELETE record. What about the code for the update/insert.
And where is the scipt that handles the insert and/or update request?

And show that code within the appropriate code tags, as requested before.

Ronald
onlymars's Avatar
Newbie
 
Join Date: Mar 2008
Posts: 13
#4: Mar 31 '08

re: Updating PHP Generated Form


Sorry man i am a newcomer to this forum thats y didn't knew the tags. i am reaind the records from mysql but am not sure how to catch them on my update page, the delete and insert new records page's are easy but i am stuck in update page cause all the textboxes will have the same name making it a aray of values, so how do i catch them on next page and update the values. Thanx
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#5: Mar 31 '08

re: Updating PHP Generated Form


You want us to guess what your code looks like? Or are you looking for a freebie?
You show (part of) a script that works ok to you but you don't want to show the other code, the one that the problem is about.

When you seek help, but do not want to show any code for the form and the update script you have this far, we cannot help you in any way.

Ronald
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#6: Mar 31 '08

re: Updating PHP Generated Form


Quote:

Originally Posted by onlymars

Sorry man i am a newcomer to this forum thats y didn't knew the tags. i am reaind the records from mysql but am not sure how to catch them on my update page, the delete and insert new records page's are easy but i am stuck in update page cause all the textboxes will have the same name making it a aray of values, so how do i catch them on next page and update the values. Thanx

An update is usually done by the primary key (or Unique field) of the table.

the key (if not relevant for the user) is usually in a hidden input field.

To make an update, your SQL would look something like this:
Expand|Select|Wrap|Line Numbers
  1. UPDATE tableName SET fieldName = " . $variable . "...  WHERE primaryKeyField = " . $value; 
I don't know what your table looks like, but if you post it we can help you make an update SQL statement if you can't figure it out.

good luck,

DM
onlymars's Avatar
Newbie
 
Join Date: Mar 2008
Posts: 13
#7: Mar 31 '08

re: Updating PHP Generated Form


ok folks i am hell sorry to all u, i dont know how to get u people understand my problem, here is the code
Expand|Select|Wrap|Line Numbers
  1.    $checked= $_POST['check'];
  2.  
  3.     $ids = (is_array($checked)) ? implode(',', $checked) : $checked;
  4.     mysql_query ("UPDATE currency SET curr_amount IN($ids)");
  5.  
this page recieves the array of values but is unable to update the table, if u fellows dont undertand it yet again then plz dont mind i will send u both pages code in some time.
thanx for ur patience
onlymars's Avatar
Newbie
 
Join Date: Mar 2008
Posts: 13
#8: Apr 1 '08

re: Updating PHP Generated Form


helloo guys i have the code now with me, sorry for being alil late, this is my entry.php code
Expand|Select|Wrap|Line Numbers
  1.         echo "<table width='100%'>";
  2.     while($curr=mysql_fetch_array($result2))
  3.     {
  4.     $a=$curr['curr_name'];
  5.     $b=$curr['curr_amount'];
  6.  
  7.  
  8.     echo "<tr><td class='style4' width='100'>";        
  9.  
  10.  
  11.     echo "<input name='name[]' class='style4' size='15' value='" . $a . "'>";
  12.     echo "<td class='style4' width='100'>";
  13.     echo "<input name='amount[]' class='style4' size='15' value='" . $b . "'>";
  14.  
  15.     }
  16.     echo "</table>";
  17.  
and here is my update.php code,
Expand|Select|Wrap|Line Numbers
  1. $name= $_POST['name'];
  2. $amount=$_POST['amount'];
  3.  
  4.  
  5. $ids = (is_array($name)) ? implode(',', $name) : $name;
  6. mysql_query ("UPDATE currency SET curr_name IN($ids)");
  7.  
  8. $ids2 = (is_array($amount)) ? implode(',', $amount) : $amount;
  9. mysql_query ("UPDATE currency SET curr_amount IN($ids2)");
  10.  
  11.  
  12. echo $ids . "<br>";
  13. echo $ids2;
  14.  
i receives all the values from text boxes as i have printed them in last lines so that i can see if it gets the array. so i recieve all the values but i guess i am not writing the update line correct, while if i write delete insteate of update then it works but something is wrong with update.
Reply