| | |
extracting table field to html form then inserting values back in database
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Dec 2008
Posts: 57
Reputation:
Solved Threads: 0
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?
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?
Yeah, possible. Have a hidden field in the form to store the id. When the user clicks submit, update the table 

mysql Syntax (Toggle Plain Text)
UPDATE table SET orderno='".$_POST['orderno']."' WHERE id='".$_POST['id']."'";
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
Okay.. This is a sloppy example, just to give you an idea.
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.
php Syntax (Toggle Plain Text)
<?php if(isset($_POST['submit'])) { print "<pre>"; print "Id array => <br />"; print_r($_POST['id']); print "Order no array => <br />"; print_r($_POST['orderno']); print "</pre>"; for($i=0;$i< count($_POST['orderno']); $i++) { //there will be equal number of elements in both id array and orderno array. echo $_POST['id'][$i]." -> ".$_POST['orderno'][$i]."<br />"; } } ?> <html> <body> <form method="post"> <?php for($i=0;$i<5;$i++) { ?> <input type='hidden' name='id[]' value='<?php echo $i; ?>'> Order <?php echo $i; ?>:<input type="text" name="orderno[]"><br /> <?php } ?> <input type="submit" name="submit" value="submit"> </form> </body> </html>
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*
*PM asking for help will be ignored*
![]() |
Other Threads in the PHP Forum
- Previous Thread: url-rewriting
- Next Thread: How to create a hyperlink for a text from database
| Thread Tools | Search this Thread |
ajax apache api array basics beginner binary broken cakephp checkbox class cms code codingproblem combobox cron curl database date display domain dynamic echo email error file files folder form format forms function functions google href htaccess html image include insert interactive ip java javascript joomla js limit link load login mail malfunctioning menu mlm mobile multiple mysql nodes oop outofmemmory paging parse paypal pdf php problem procedure query radio ram random recursion reference remote return script search server sessions sms source space sql syntax system table tutorial unset up-to-date update upload url validation validator variable video web webapplications websitecontactform youtube






