extracting table field to html form then inserting values back in database

Thread Solved

Join Date: Dec 2008
Posts: 57
Reputation: khr2003 is an unknown quantity at this point 
Solved Threads: 0
khr2003 khr2003 is offline Offline
Junior Poster in Training

extracting table field to html form then inserting values back in database

 
0
  #1
Mar 3rd, 2009
hi
I have a table in my database that look like this:
id - name - orderno

the table has data in the fields of id and name but orderno is empty.
I made a html form based on the data of this field, in front of each name field there is an text input field. when the user submits the data I want every value in the text input field to be inserted in the orderno of the relevant id.

is this possible?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,746
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: extracting table field to html form then inserting values back in database

 
0
  #2
Mar 3rd, 2009
Yeah, possible. Have a hidden field in the form to store the id. When the user clicks submit, update the table
  1. UPDATE table SET orderno='".$_POST['orderno']."' WHERE id='".$_POST['id']."'";
  2.  
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 57
Reputation: khr2003 is an unknown quantity at this point 
Solved Threads: 0
khr2003 khr2003 is offline Offline
Junior Poster in Training

Re: extracting table field to html form then inserting values back in database

 
0
  #3
Mar 3rd, 2009
thanks for the reply, that is what I did.
However, I was wondering how would I do it for more than one field. I tired to name the text input "orderno[]" and then use foreach loop to extract the values, but I could not assign each of the values to its related id.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,746
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: extracting table field to html form then inserting values back in database

 
0
  #4
Mar 4th, 2009
Okay.. This is a sloppy example, just to give you an idea.
  1. <?php
  2. if(isset($_POST['submit'])) {
  3. print "<pre>";
  4. print "Id array => <br />";
  5. print_r($_POST['id']);
  6. print "Order no array => <br />";
  7. print_r($_POST['orderno']);
  8. print "</pre>";
  9. for($i=0;$i< count($_POST['orderno']); $i++) { //there will be equal number of elements in both id array and orderno array.
  10. echo $_POST['id'][$i]." -> ".$_POST['orderno'][$i]."<br />";
  11. }
  12. }
  13. ?>
  14. <html>
  15. <body>
  16. <form method="post">
  17. <?php
  18. for($i=0;$i<5;$i++) {
  19. ?>
  20. <input type='hidden' name='id[]' value='<?php echo $i; ?>'>
  21. Order <?php echo $i; ?>:<input type="text" name="orderno[]"><br />
  22. <?php
  23. }
  24. ?>
  25. <input type="submit" name="submit" value="submit">
  26. </form>
  27. </body>
  28. </html>
Instead of for loop, you will have while($row = mysql_fetch_array($result)) . Instead of assigning $i as value to the hidden field, you will have the counter/id field of the table.
You can then map the values of the array entered by the user in the orderno field to id field.
Last edited by nav33n; Mar 4th, 2009 at 12:04 am. Reason: some more addition..
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 57
Reputation: khr2003 is an unknown quantity at this point 
Solved Threads: 0
khr2003 khr2003 is offline Offline
Junior Poster in Training

Re: extracting table field to html form then inserting values back in database

 
0
  #5
Mar 4th, 2009
thank you very much. worked after some modifications.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,746
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: extracting table field to html form then inserting values back in database

 
0
  #6
Mar 4th, 2009
You are welcome Cheers!
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC