| | |
Get Variables values
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
When you setup the textbox fields, make sure they both have names and that their names are unique. So something like below is an example:
Then to retrieve those 2 fields and display them you would use the following php code:
So try to make sure the field names are unique and in the form element it has method=post
html Syntax (Toggle Plain Text)
<form method='post'> <input type='text' name='box1' size=30><br> <input type='text' name='box2' size=30> </form>
php Syntax (Toggle Plain Text)
echo $_POST['box1']; //displays first field in above example echo "<br>"; // adds new html line. echo $_POST['box2']; //displays second field in above example
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
I have just done a few tests and I don't see how it is possible to have the two name= fields exactly identicle but what you can do is put arrays in the name= fields and retrieve the $_POST as a 2 dimensional array. Below is an example of what I have done.
Also you need to click the submit button for the above example to work. The above example shows about displaying what information the $_POST array holds and shows about using 2 dimensional $_POST arrays. Other than using arrays in the name= field,or changing the name of the field to be unique, you will find that only the last field of its duplicate name will be recorded in php.
php Syntax (Toggle Plain Text)
<form method='post'> <input type='text' name='test[0]' value='111'><br> <input type='text' name='test[1]' value='222'><input type=submit value='submit'></form><br> <? var_dump($_POST); //dumps the variable echo "<p><hr>"; echo $_POST['test'][0]; echo "<br>"; echo $_POST['test'][1]; ?>
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
well I found the way to solve this issue:
php Syntax (Toggle Plain Text)
<form method='post'> <input name="test[]" type="text" /> <input name="test[]" type="text" /> <br> <input type=submit value=submit> </form> <? echo $test[0]."<br>".$test[1]; ?>
Last edited by peter_budo; Nov 27th, 2008 at 7:51 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Best regards,
zanzo
zanzo
•
•
•
•
I have two input textbox with the same name, when submiting the page I get only the value of the second textbox.
how can i get the value of both fields???
php Syntax (Toggle Plain Text)
<table width="287" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="5"><form id="form" name="form" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <table width="285" border="0" cellspacing="0" cellpadding="0"> <tr> <td> </td> <td>name</td> <td><input type="text" name="cool" /></td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td>address</td> <td><input type="text" name="cool" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Submit" /></td> <td> </td> </tr> </table> </form> </td> </tr> <tr> <td width="129"><?php if(isset($_POST['Submit'])) { echo "name".$_POST['cool']; echo "adderss".$_POST['cool']; } else { echo "yu didn't click in go button"; } ?></td> <td width="76"> </td> <td width="76"> </td> <td width="76"> </td> <td width="5"> </td> </tr> </table>
Last edited by peter_budo; Nov 27th, 2008 at 7:53 pm. Reason: Please use [code] not <code>
Actually it doesn't work !!! But I fixed it and it works like that:
php Syntax (Toggle Plain Text)
<table width="287" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="5"><form id="form" name="form" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <table width="285" border="0" cellspacing="0" cellpadding="0"> <tr> <td> </td> <td>name</td> <td><input type="text" name="cool[]" /></td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td>address</td> <td><input type="text" name="cool[]" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Submit" /></td> <td> </td> </tr> </table> </form> </td> </tr> <tr> <td width="129"><?php if(isset($_POST['Submit'])) { echo "name".$_POST['cool'][0]; echo "adderss".$_POST['cool'][1]; } else { echo "yu didn't click in go button"; } ?></td> <td width="76"> </td> <td width="76"> </td> <td width="76"> </td> <td width="5"> </td> </tr> </table>
Last edited by peter_budo; Nov 27th, 2008 at 7:54 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Best regards,
zanzo
zanzo
•
•
Join Date: Apr 2008
Posts: 293
Reputation:
Solved Threads: 11
I think it solve your problem
<html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <table width="287" border="0" cellspacing="0" cellpadding="0"> <tr> <td colspan="5"><form id="form" name="form" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <table width="285" border="0" cellspacing="0" cellpadding="0"> <tr> <td> </td> <td>name</td> <td><input type="text" name="textfield[]" id="textfield[0]"></td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td>address</td> <td><input type="text" name="textfield[]" id="textfield[1]" /></td> </tr> <tr> <td> </td> <td><input type="submit" name="Submit" value="Submit" onClick=" return form()"/></td> <td> </td> </tr> </table> </form> </td> </tr> <tr> <td width="129"> </td> <td width="76"> </td> <td width="76"> </td> <td width="76"> </td> <td width="5"> </td> </tr> </table> </body> </html> <? echo "name =".$_POST['textfield'][0]; echo"<br>"; echo "address =".$_POST['textfield'][1]; ?>
![]() |
Similar Threads
- finding the highest value help (C)
- need help with code (C++)
- Values are getting lost! (C++)
- Help w/ constructors (Java)
- Random Java Info (Java)
- How to do constructors (Java)
- Where to get started with Web Programming (IT Professionals' Lounge)
- Pounds to Grams Conversion (C++)
- Need help with Const, Ref and Classes. (C)
- Objects (C)
Other Threads in the PHP Forum
- Previous Thread: Is Online chatting done with php?
- Next Thread: Square thumbnail php
| Thread Tools | Search this Thread |
advanced apache api array basics beginner binary broken cakephp check checkbox class cms code codingproblem combobox cookies cron curl database date datepart display dynamic echo email error file files folder form forms function functions google head href htaccess html image include includingmysecondfileinthechain insert ip javascript job joomla js limit link login mail menu mlm mobile multiple mysql oop outofmemmory paging parse password paypal pdf php problem procedure query radio ram random recursion remote script search server sessions smarty sms source space sql stored syntax system table traffic tutorial unicode up-to-date update upload url validator variable video web webapplications websitecontactform youtube






