Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<pre>1.I want to Enter Multiple values into one Input in HTML Form You can see my hint from the given code below. 

2.This is not the Right code that I need. In this code I enter one Value Into Input One time But I need to Enter more Value in one Input 

<input type="text" name = "number1" size="20">

3.I want Answer only use For loop and Array 
please give me proper Full right code



 <html>
<body>
<form method="post">
<input type="text" name = "number1" size="20">
Enter First Number:
<input  type="submit" name="submit" value="Add">
</form>
<?php
    if(isset($_POST['submit']))
    {
     $number1 = $_POST['number1'];
$tex = array( );
$tex[0] = $number1 ;

  $sum=0;
for ($x = 0; $x <= 5; $x++) {
$sum = $sum + $tex[0];
  echo "The number is: $sum <br>";
}
}
?>
</body>
</html>


What I have tried:

PHP
<pre>if(isset($_POST['submit']))
    {
     $number1 = $_POST['number1'];
$tex = array( );
$tex[0] = $number1 ;

  $sum=0;
for ($x = 0; $x <= 5; $x++) {
$sum = $sum + $tex[0];
  echo "The number is: $sum <br>";
}
}
Posted
Updated 25-May-21 21:14pm
v2
Comments
Richard MacCutchan 26-May-21 3:19am    
If you want multiple values in a single text box then you need to separate them with some character (e.g. 12,44,5,87,54). Your code then needs to split the string into its different parts before storing them in the array. But relying on users to get that right every time is a big ask.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900