473,395 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Form input name from a variable

18
One more question...
I have pulled my query line by line into my php form. Each line/row will have an input field. How can I dynamically assign a variable to the "name" field, for instance if I want the name= to be the value of the item_no.


My updated code:

Expand|Select|Wrap|Line Numbers
  1. <form action="inventorymaster_form.php" method="post" name="inventorymaster_form" align="left" class="style3" bgcolor="#ffffff" onSubmit="return verifyForm(this);">
  2.  
  3. <legend>INVENTORYMASTER</legend>
  4. <table border="1" class="mainmenu" border="0" cellpadding="0" cellspacing="0">
  5. <?php
  6. $i=0;
  7. while ($i<$num) {
  8. $f1=mysql_result($result,$i,"id");
  9. $f2=mysql_result($result,$i,"Vendor");
  10. $f3=mysql_result($result,$i,"item_no");
  11. $f4=mysql_result($result,$i,"description");
  12. ?>
  13. <tr>
  14. <td> &nbsp &nbsp <?php echo $f1;?>&nbsp &nbsp </td>
  15. <td> &nbsp &nbsp <?php echo $f2;?>&nbsp &nbsp </td>
  16. <td> &nbsp &nbsp <?php echo $f3;?>&nbsp &nbsp </td>
  17. <td> &nbsp &nbsp <?php echo $f4;?>&nbsp &nbsp </td>
  18. <td align="center"> <input type='text' name=$f3 value="<?php echo "$i";?>">
  19.  
  20. </tr>
  21. <?php
  22. $i++;
  23. }
  24. ?>
  25. </table>
  26. </form>
Thanks again,
MO
Sep 21 '09 #1
5 4839
TheServant
1,168 Expert 1GB
I am a little confused at what you want. First thing though:
Line 18 has name=$f3
Should be name="<?php echo $f3; ?>" like you ahve for the others.

Second, why don't you include your output (echo) in a loop - like for example in your while loop? Would that be what you want?
Sep 21 '09 #2
prabirchoudhury
162 100+
yap ,TheServant right . i am adding few more thing

1. echo the php variables in right way
2. space between two var in while condition while ($i < $num)
3. mysql_result() function is slower than mysql_fetch_row(), mysql_fetch_array(), mysql_fetch_assoc() and mysql_fetch_object().


cheers

:)
Sep 22 '09 #3
Atli
5,058 Expert 4TB
Hey.

You can assign array indexes to the name of a input tag.

For example:
Expand|Select|Wrap|Line Numbers
  1. <input type='text' name='value[1]' value='first' /><br />
  2. <input type='text' name='value[2]' value='second' /><br />
  3. <input type='text' name='value[3]' value='third' /><br />
  4. <input type='text' name='value[4]' value='fourth' />
Submitted to PHP, the $_POST['value'] element would be an array
Expand|Select|Wrap|Line Numbers
  1. Array
  2. (
  3.     [1] => first
  4.     [2] => second
  5.     [3] => third
  6.     [4] => fourth
  7. )
  8.  
You could create input boxes for whichever columns you needed updated, using the name of the column as they input name, and then put the ID of the column in as the array index.
Sep 22 '09 #4
Atli
5,058 Expert 4TB
@TheServant
It *is* inside his loop. Take a closer look ;-)
@prabirchoudhury
#1. There is no "right" way to echo variables. Only "preferred" ways. (Given that it is syntactically correct, of course. (Which it is))
Sure, the method he uses is usually considered a bit sloppy, but it is in no way "wrong".

#2. This doesn't matter in the slightest, and is to a matter of personal preference. Many programmers actually prefer not to leave white-spaces in their conditional statements.

Not trying to sound argumentative here, but...
Sep 22 '09 #5
TheServant
1,168 Expert 1GB
@Atli
My mistake. Thanks Atli ;)
Sep 22 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Randell D. | last post by:
HELP! I am determined to stick with this... I'm getting there... for those who haven't read my earlier posts, I'm createing what should be a simple function that I can call to check that...
14
by: Oleg | last post by:
Hello there: I've been trying to create two different sets of required fields in one form and to use a radiobutton as sort of a switcher between these sets. In my HTML form there are two...
2
by: umashd | last post by:
Hi, I am doing a web based project for my graduation. I studied bit of java for backend processesing and javascript for the client. Here is the scenario. In the FORM, I use INPUT TYPE=text...
5
by: Navillus | last post by:
Hey gang, I have a login form that is empty by default, but can be filled with values from a previous form: <input type=text maxlength="40" size="40" name="user" value="`usr`"> <input...
4
by: jedimasta | last post by:
Good evening all, I'm a relatively new to javascript, but I've been working with ColdFusion and PHP for years so I'm not necessarily ignorant, just stuck and frustrated. Using ColdFusion I'm...
10
by: Girish | last post by:
Hi Everyone, I am passing a form to a php script for further processing. I am able to retrieve the last value set for that given form variable using $variable=$_REQUEST;
4
by: Greg Scharlemann | last post by:
I'm trying to setup a dyamic dropdown list that displays a number of text fields based on the selected number in the dropdown. The problem I am running into is capturing the data already entered...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
26
by: Jerim79 | last post by:
I need to create a form that takes a number that the user enters, and duplicates a question the number of times the user entered. For instance, if the customer enters 5 on the first page, when...
3
uranuskid
by: uranuskid | last post by:
Hey folks, I was going to include a contact form on my website. Well, in the first place that seemed an easy thing to do with a form that prompts a PHP file validating the input vaiables and using...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.