-1
for($i = 1; $i <= 1; $i++) {
    $you_item[$i] = ucwords($_POST['you_item'.$i.'']);
    $you_item[$i] = "http://steamcommunity.com/market/priceoverview/?appid=570&currency=1&market_hash_name=".$you_item[$i]."";
    $you_item[$i] = str_replace(' ', '%20', $you_item[$i]);
    $you_item[$i] = file_get_contents($you_item[$i]);
    $you_item[$i] = json_decode($you_item[$i], true);
    $you_item[$i] = $you_item[$i]['median_price'];
    $you_item[$i] = preg_replace("/&#?[a-z0-9]{2,8};/i","", $you_item[$i]);
    echo $you_item[$i];
}

the sample site is this http://bit.ly/1gKGoN0

I have a problem on the loop of getting the value from the textboxes

i declared the form like this

<?php for($i=1;$i<=15;$i++){ ?> <input type="text" name="<?php echo
"you_item".$i.""?>" /> <?php } ?>

but the problem now is i cant get the value from the textboxes where i forwarded to $you_item[$i]. the site that i made doesnt have a loop. i coded the $you_item1 upto 15 because i have 15 textboxes. can someone help me out?

scrowler
  • 24,273
  • 9
  • 60
  • 92
Marverick
  • 117
  • 1
  • 9
  • You should use arrays for input elements. http://stackoverflow.com/questions/3314567/how-to-get-form-input-array-into-php-array – Maximus2012 Jul 20 '15 at 22:05
  • 1
    You made a mistake naming your input field. Its name corresponds to `you_item1`, `you_item2` and that's not how we do things. Your fields should be declared like this: ``. When submitted to the PHP script, you'll have an array in `$_POST['you_item']` that you can access via numeric indexes, such as `$_POST['you_item'][0]`, `$_POST['you_item'][1]` etc. – N.B. Jul 20 '15 at 22:08

1 Answers1

0

try to change,

<?php for($i=1;$i<=15;$i++){ ?> <input type="text" name="<?php echo
"you_item".$i.""?>" /> <?php } ?>

to

<input type="text" name="you_item[]" /> 
  • how about the for($i = 1; $i <= 1; $i++) { $you_item[$i] = ucwords($_POST['you_item'.$i.'']); $you_item[$i] = "http://steamcommunity.com/market/priceoverview/?appid=570&currency=1&market_hash_name=".$you_item[$i].""; $you_item[$i] = str_replace(' ', '%20', $you_item[$i]); $you_item[$i] = file_get_contents($you_item[$i]); $you_item[$i] = json_decode($you_item[$i], true); $you_item[$i] = $you_item[$i]['median_price']; $you_item[$i] = preg_replace("/?[a-z0-9]{2,8};/i","", $you_item[$i]); echo $you_item[$i]; } – Marverick Jul 20 '15 at 22:17
  • you are not getting the actually, we can write as many number of text boxes like 1
    2
    3, and get all the entered values by running loop over $_POST['you_item'][$i]
    –  Jul 20 '15 at 22:23