Jump to content

array


derrick katungi

Recommended Posts

<?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.

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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);

?>

Link to comment
Share on other sites

<!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>&nbsp </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>&nbsp </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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.