Jump to content
WesleyA

Do you need an array when inserting multiple fileds in mysql dbase?

Recommended Posts

The idea is to insert with the browser a multiple input field, a loop, into mysql database.

 

Is the solution to first put this loop input variable in an array and after that create in this case multible tables?

 

Or is an array not necessary?

Share this post


Link to post
Share on other sites

Arrays are never really necessary, they just make it easier to deal with related data. Without an array you couldn't really use a loop, for example. If you want to do that in a loop then use an array.

Share this post


Link to post
Share on other sites

If its easier and you need it for a loop then I go fo the array.

 

I'm stuck with the following script.

     <?php     echo "<form method = 'POST' target = '_blank'>";		for($x = 0; $x < 5; $x++)		{			echo "<input type = 'text' name = 'runame' /></br>";		}		echo "<input type = 'submit' value = 'send' /> ";			echo "</from>";          ////         if (isset($_POST['runame']))  {         $runame = $_POST['runame'];		for($x = 0; $x < 5; $x++){		$test[$x] = array($runame => $x);											}									}      if (isset ($test)) {			echo "<pre>";			for($x = 0; $x < 5; $x++){			print_r($test[$x]);					}			echo "</pre>";					}         ?>

Only the last entry is taken. I also want the first four entries.

Share this post


Link to post
Share on other sites

yeah I was figuring out something in that direction, but just adding [] to runame is not possible, in array it gives a fatal error report due to [].

Edited by WesleyA

Share this post


Link to post
Share on other sites

You don't need for loop for print_r

 

You can have array within array as you original wanted with

        <?php        echo "<form method = 'POST' target = '_blank'>";        for ($x = 0; $x < 5; $x++) {            echo "<input type = 'text' name = 'runame[]' value='aaaa" . $x . "' /></br>";        }        echo "<input type = 'submit' value = 'send' /> ";        echo "</from>";        if (isset($_POST['runame'])) {            $runame = $_POST['runame'];            for ($x = 0; $x < 5; $x++) {                $test[$x] = array($runame[$x]);            }        }        if (isset($test)) {            echo "<pre>";            //for ($x = 0; $x < 5; $x++) {            print_r($test);            // }            echo "</pre>";        }        ?>

or one single array, but you would get same result just with print_r($runame); without adding to another array that is storing the same values.

    <body>        <?php        echo "<form method = 'POST' target = '_blank'>";        for ($x = 0; $x < 5; $x++) {            echo "<input type = 'text' name = 'runame[]' value='aaaa" . $x . "' /></br>";        }        echo "<input type = 'submit' value = 'send' /> ";        echo "</from>";        if (isset($_POST['runame'])) {            $runame = $_POST['runame'];            for ($x = 0; $x < 5; $x++) {                $test[$x] = $runame[$x];            }        }        if (isset($test)) {            echo "<pre>";            //for ($x = 0; $x < 5; $x++) {            print_r($test);            // }            echo "</pre>";        }        ?>

Share this post


Link to post
Share on other sites

Is it one way or another possible to put php code inside a html input tag?

 

I was looking for a html tag to identify exactly how an input variable should have an index.

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...