Get Variables values

Thread Solved

Join Date: Feb 2008
Posts: 58
Reputation: zanzo is an unknown quantity at this point 
Solved Threads: 0
zanzo's Avatar
zanzo zanzo is offline Offline
Junior Poster in Training

Get Variables values

 
0
  #1
Nov 25th, 2008
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???
Best regards,
zanzo
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,533
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 137
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Posting Virtuoso

Re: Get Variables values

 
0
  #2
Nov 25th, 2008
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:
  1. <form method='post'>
  2. <input type='text' name='box1' size=30><br>
  3. <input type='text' name='box2' size=30>
  4. </form>
Then to retrieve those 2 fields and display them you would use the following php code:
  1. echo $_POST['box1']; //displays first field in above example
  2. echo "<br>"; // adds new html line.
  3. echo $_POST['box2']; //displays second field in above example
So try to make sure the field names are unique and in the form element it has method=post
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*`
My favourite PC. - Oopy Doopy Do 2U2!
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 58
Reputation: zanzo is an unknown quantity at this point 
Solved Threads: 0
zanzo's Avatar
zanzo zanzo is offline Offline
Junior Poster in Training

Re: Get Variables values

 
0
  #3
Nov 25th, 2008
The textboxes should have similar names. In asp I get the values of both separated by commas, how to get that in php
Best regards,
zanzo
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,533
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 137
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Posting Virtuoso

Re: Get Variables values

 
0
  #4
Nov 25th, 2008
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.
  1. <form method='post'>
  2. <input type='text' name='test[0]' value='111'><br>
  3. <input type='text' name='test[1]' value='222'><input type=submit value='submit'></form><br>
  4. <?
  5. var_dump($_POST); //dumps the variable
  6. echo "<p><hr>";
  7. echo $_POST['test'][0];
  8. echo "<br>";
  9. echo $_POST['test'][1];
  10. ?>
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.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*`
My favourite PC. - Oopy Doopy Do 2U2!
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 58
Reputation: zanzo is an unknown quantity at this point 
Solved Threads: 0
zanzo's Avatar
zanzo zanzo is offline Offline
Junior Poster in Training

Re: Get Variables values

 
0
  #5
Nov 25th, 2008
well I found the way to solve this issue:

  1. <form method='post'>
  2.  
  3. <input name="test[]" type="text" />
  4. <input name="test[]" type="text" />
  5. <br>
  6. <input type=submit value=submit>
  7. </form>
  8.  
  9. <?
  10. echo $test[0]."<br>".$test[1];
  11. ?>
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 46
Reputation: rohitrohitrohit is an unknown quantity at this point 
Solved Threads: 3
rohitrohitrohit's Avatar
rohitrohitrohit rohitrohitrohit is offline Offline
Light Poster

Re: Get Variables values

 
0
  #6
Nov 26th, 2008
Originally Posted by zanzo View Post
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???
i think same name textbox have to display there value.i tried some code [php].they are executing well.if u have still proble... then use id for controls.below code working good.............
  1. <table width="287" border="0" cellspacing="0" cellpadding="0">
  2.  
  3. <tr>
  4. <td colspan="5"><form id="form" name="form" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  5. <table width="285" border="0" cellspacing="0" cellpadding="0">
  6.  
  7. <tr>
  8. <td>&nbsp;</td>
  9. <td>name</td>
  10. <td><input type="text" name="cool" /></td>
  11. </tr>
  12. <tr>
  13. <td>&nbsp;</td>
  14. <td>&nbsp;</td>
  15. <td>&nbsp;</td>
  16. </tr>
  17. <tr>
  18. <td>&nbsp;</td>
  19. <td>address</td>
  20. <td><input type="text" name="cool" /></td>
  21. </tr>
  22. <tr>
  23. <td>&nbsp;</td>
  24. <td><input type="submit" name="Submit" value="Submit" /></td>
  25. <td>&nbsp;</td>
  26. </tr>
  27. </table>
  28. </form> </td>
  29. </tr>
  30.  
  31. <tr>
  32. <td width="129"><?php
  33. if(isset($_POST['Submit']))
  34. {
  35. echo "name".$_POST['cool'];
  36. echo "adderss".$_POST['cool'];
  37. }
  38. else
  39. {
  40. echo "yu didn't click in go button";
  41. }
  42. ?></td>
  43. <td width="76">&nbsp;</td>
  44. <td width="76">&nbsp;</td>
  45. <td width="76">&nbsp;</td>
  46. <td width="5">&nbsp;</td>
  47. </tr>
  48. </table>
Last edited by peter_budo; Nov 27th, 2008 at 7:53 pm. Reason: Please use [code] not <code>
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 58
Reputation: zanzo is an unknown quantity at this point 
Solved Threads: 0
zanzo's Avatar
zanzo zanzo is offline Offline
Junior Poster in Training

Re: Get Variables values

 
0
  #7
Nov 26th, 2008
Actually it doesn't work !!! But I fixed it and it works like that:

  1. <table width="287" border="0" cellspacing="0" cellpadding="0">
  2.  
  3. <tr>
  4. <td colspan="5"><form id="form" name="form" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  5. <table width="285" border="0" cellspacing="0" cellpadding="0">
  6.  
  7. <tr>
  8. <td>&nbsp;</td>
  9. <td>name</td>
  10. <td><input type="text" name="cool[]" /></td>
  11. </tr>
  12. <tr>
  13. <td>&nbsp;</td>
  14. <td>&nbsp;</td>
  15. <td>&nbsp;</td>
  16. </tr>
  17. <tr>
  18. <td>&nbsp;</td>
  19. <td>address</td>
  20. <td><input type="text" name="cool[]" /></td>
  21. </tr>
  22. <tr>
  23. <td>&nbsp;</td>
  24. <td><input type="submit" name="Submit" value="Submit" /></td>
  25. <td>&nbsp;</td>
  26. </tr>
  27. </table>
  28. </form> </td>
  29. </tr>
  30.  
  31. <tr>
  32. <td width="129"><?php
  33. if(isset($_POST['Submit']))
  34. {
  35. echo "name".$_POST['cool'][0];
  36. echo "adderss".$_POST['cool'][1];
  37. }
  38. else
  39. {
  40. echo "yu didn't click in go button";
  41. }
  42. ?></td>
  43. <td width="76">&nbsp;</td>
  44. <td width="76">&nbsp;</td>
  45. <td width="76">&nbsp;</td>
  46. <td width="5">&nbsp;</td>
  47. </tr>
  48. </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
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 296
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: Get Variables values

 
0
  #8
Nov 26th, 2008
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>&nbsp;</td>
<td>name</td>
<td><input type="text" name="textfield[]"  id="textfield[0]"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>address</td>
<td><input type="text" name="textfield[]"  id="textfield[1]" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"  onClick=" return form()"/></td>
<td>&nbsp;</td>
</tr>
</table>
</form> </td>
</tr>

<tr>
<td width="129">


</td>
<td width="76">&nbsp;</td>
<td width="76">&nbsp;</td>
<td width="76">&nbsp;</td>
<td width="5">&nbsp;</td>
</tr>
</table>
</body>
</html>
<? 
echo "name =".$_POST['textfield'][0];
echo"<br>";
echo "address =".$_POST['textfield'][1];
?>
Reply With Quote Quick reply to this message  
Reply

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




Views: 681 | Replies: 7
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC