I am building my Major Project using PHP and Oracle. Project is basically a replica of phpMyAdmin.
I am building the same kind of admin-panel for oracle using PHP.
I have a doubt…
Like in phpMyAdmin, while creating a new database table it asks for number of columns, I want to implement the same thing. But the problem is, on the next page, how do I print the number of text input fields as per the user’s input. To better explain, I have taken the screenshot of what I want to do-
So question is - How can I make such a code in PHP which gives same number of input field set as the user input and also how can I get different variable names to store them?
Example - let’s say I inputed 2 in number of columns field, so I must be presented with 2 set’s of input field sets(including name,type etc.)
Now I want to transfer these two set’s of field to a query that will save the data to Oracle server.
So I need different variables to store each input like name1 for name from field set 1 similarly name2 for name from field set 2 and so on…
<?php
#increase error reporting
error_reporting(-1);
ini_set('display_errors', true);
#if we have a rows variable and it's not empty
#convert it to an integer, otherwise, use 0.
$rows = empty($_POST['rows']) ? 0 : (int)$_POST['rows'] ;
?>
<html>
<head>
<title>Demo</title>
</head>
<body>
<form action="#" method="post">
<div>
<p>
Number of people to add?
</p>
<input type="text" name="rows" />
</div>
<!-- If the nummber of $rows is not 0 -->
<?php if(0 !== $rows): ?>
<!-- create loop which loops the number of times defined in $rows -->
<?php foreach(range(1, $rows) as $row): ?>
<div>
<p>Person <?php echo $row; ?></p>
<!-- Create a PHP array compatible set of inputs, using $row as the index -->
<input type="text" name="people[<?php echo $row; ?>][forename]" />
<input type="text" name="people[<?php echo $row; ?>][surname]" />
</div>
<?php endforeach; ?>
<?php endif; ?>
<input type="submit" value="Add" />
</form>
</body>
</html>
Ok, so I tried to make a small thing out my self but don’t know where am I suppose I am not able to operate with arrays properly. Please have a look. I created 3 files -
test.php(a file consisting just a simple form)
<html>
<head>
<title>Demo</title>
</head>
<body>
<form action="next.php" method="post">
<div>
<p>
Number of people to add?
</p>
<input type="text" name="rows" />
</div>
<input type="submit" value="Add" />
</form>
</body>
</html>
next.php(test.php file has this file’s name in action)
Here I have converted your 2D array to just 1D and tried to pass the value to next page where I’ll show the input content.
Show.php(to show the output)
I really have no Idea if this is the right way to print particular array without using a for loop. Please guide me on this
<?php
$temp=$_POST["people[1]"];
echo $temp;
?>
This is the error I am getting on show.php -
Notice: Undefined index: people[1] in C:\wamp\www\phpora\show.php on line 2
Please let me know, how can I output the content input by user…