derrick katungi Posted August 23, 2011 Share Posted August 23, 2011 <?php echo = ' <form id="form1" name="form1" method="post" action="try.php"> <table width="454" border="0"> <td width="153"> <label><input type="text" name="'.$a._.$i.'" /></label></td> </td></tr></table></form>'; for($i = 1; $i <= 5; $i++) { $in[$a._.$i] = $_POST['.$a._.$i.']; } var_dump($in); ?> Help:::: i want the array $in[$a._.$i] to store the values that will be typed into the form. $a = 1 and $i is variable that changes according to the for loop. currently the var_dump($in) returns null. Quote Link to comment Share on other sites More sharing options...
voip03 Posted August 23, 2011 Share Posted August 23, 2011 echo = syntax error, unexpected '=' you need submit button Quote Link to comment Share on other sites More sharing options...
derrick katungi Posted August 23, 2011 Author Share Posted August 23, 2011 <?php echo ' <form id="form1" name="form1" method="post" action="try.php"> <table width="454" border="0"> <td width="153"> <label><input type="text" name="'.$a._.$i.'" /></label></td> </td></tr></table></form>'; if($_POST['submit']) { for($i = 1; $i <= 5; $i++) { $in[$a._.$i] = $_POST['.$a._.$i.']; } } var_dump($in); ?> Help:::: i want the array $in[$a._.$i] to store the values that will be typed into the form. $a = 1 and $i is variable that changes according to the for loop. currently the var_dump($in) returns null. when the submit button is clicked, it shows you the content in the array. Quote Link to comment Share on other sites More sharing options...
WebStyles Posted August 23, 2011 Share Posted August 23, 2011 I really don't know what you mean. Are you just trying to add an underscore between $a and $i ? then try this: <?php echo '<form id="form1" name="form1" method="post" action="try.php"> <table width="454" border="0"> <td width="153"> <label><input type="text" name="'.$a.'_'.$i.'" /></label></td> </td></tr></table></form>'; foreach($in = 1; $i <= 5; $i++) { $in[$a.'_'.$i] = $_POST[$a.'_'.$i]; } var_dump($in); ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 23, 2011 Share Posted August 23, 2011 Your $a variable is not set to anything, so of course var_dump($in) returns null. Anyways, you should be using an array name for your form fields, rather than trying to make a series of named/numbered fields - http://www.php.net/manual/en/faq.html.php#faq.html.arrays Quote Link to comment Share on other sites More sharing options...
derrick katungi Posted August 23, 2011 Author Share Posted August 23, 2011 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="styler.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- body { background-color:#666666; } --> </style></head> <body> <div class="par3"> <div style="width:800px;height:auto; -webkit-border-radius: 41px 42px 44px 41px; -moz-border-radius: 41px 42px 44px 41px; border-radius: 41px 42px 44px 41px; border: 6px solid #FFFFFF; background-color:#FFFF66;"> <div class="par1"> <p><p> </p></p> <form id="form1" name="form1" method="post" action="process.php"> <label></label> <table width="340" height="32" border="0"> <tr> <td width="83">First Number </td> <td width="147"><input type="text" name="fno1" id="textfield" /></td> <!--for text area--> <td width="96"><input type="submit" name="button" id="button" value="GO" /></td> <!--for button--> </tr> </table> </form> </div> <div class="par2"> <p> <?php error_reporting(0); $number1 = $_POST['fno1']; $inputText = "input"; echo '<p>  </p>'; echo '<table width="" border="1">'; echo '<tr><td width="147">num1</td>'; echo '<td width="147">num2</td>'; echo '<td width="147">num3</td></tr></table>'; // loop for producing the required number of inputs echo '<form id="form1" name="form1" method="post" action="">'; echo '<table width="454" border="1">'; for($i = 1; $i <= $number1; $i++) { $input = 0; $x = 0; $a = 1; $b = 2; $c = 3; echo '<tr><td width="144" height="">'; echo '<input type="text" name="'.$inputText.$a.'_'.$i.'" /></td>'; echo '<td width="144">'; echo '<input type="text" name="'.$inputText.$b.'_'.$i.'" /></td>'; echo '<td width="29">'; echo '<input type="text" name="'.$inputText.$c.'_'.$i.'" />'; echo '</td></tr>'; } echo '<form id="form2" name="form2" method="post" action="process.php">'; echo '<tr><td width="29" colspan="3" align="right">'; echo '<input type="submit" name="button" id="button" value="Evaluate" />'; echo '</td></tr></form>'; echo '<p>  </p>'; if($_POST['button']) { for($i = 1; $i <= $number1; $i++) { $in[$inputText.$a.'_'.$i] = $_POST[$inputText.$a.'_'.$i]; $out[$inputText.$b.'_'.$i] = $_POST[$inputText.$b.'_'.$i]; $num[$inputText.$c.'_'.$i] = $_POST[$inputText.$c.'_'.$i]; } print_r($in); echo "<br>"; print_r($out); echo "<br>"; print_r($num); echo "<br>"; var_dump($in); var_dump($out); var_dump($num); } ?> <p> </p> </div> </div> </div> </body> </html> this is the whole code. i want 3 arrays to store data that will be input in the 3 columns i.e. -the first column should have its own array. -the second column should have its own array. -the third column should have its own array. i hope its more clear now. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 24, 2011 Share Posted August 24, 2011 error_reporting(0); Setting error reporting to zero is hiding the error messages that would help you find the problems in your code. When learning php, developing php code, or debugging php code, you should have error_reporting set to E_ALL and display_errors set to ON so that all the php detected errors will be reported and displayed. Quote Link to comment Share on other sites More sharing options...
derrick katungi Posted August 25, 2011 Author Share Posted August 25, 2011 thanks Guru... this code stores input in an array and then outputs the contents.. <td width="169"> <input type="text" name="$in[]" /></td> <td width="169"> <?php if($_POST['submit']) { var_dump($_POST); $inn = $_POST['$in']; print_r($inn); echo "<br>"; print_r($inn[1]); } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.