0

input names " option[][width] " as I want 2 input multiplication, but it doesn’t crash. input name such please.

<?php 
    $height = null; 
    $width = null; 
    function vir2nok($data) { 
        return str_replace(",",".",$data); 
    } 
    if ($_POST) { 
        $height = vir2nok($_POST["height"]); 
        $width = vir2nok($_POST["width"]); 
        if (is_numeric($height) && is_numeric($width)) { 
            $sonuc = $height * $width; 
            echo $height." x ".$width." = ".$sonuc."<hr>"; 
        } 
    } 
?> 


<form action="" method="post"> 

<input type="text" name="option[<?php echo $option['product_option_id']; ?>][height]"  placeholder="<?php echo $label_height; ?>" id="input-option<?php echo $option['product_option_id']; ?>" class="pso-height-input form-control" />
<input type="text" name="option[<?php echo $option['product_option_id']; ?>][width]"  placeholder="<?php echo $label_width; ?>" id="input-option<?php echo $option['product_option_id']; ?>" class="pso-width-input form-control" />

 <input type="submit" name="gonder"> 
</form>
iuf40054
  • 1
  • 3
  • Where does `$option['product_option_id'];` magically come from? Does your script have multiple forms that you didn't post in your question? – mickmackusa Feb 23 '19 at 22:53
  • "product_option_id" automatic filling ( sample name="option[62][height]" ) – iuf40054 Feb 23 '19 at 22:57

1 Answers1

0

You are not accessing fields properly, try to change those two lines to:

$height = vir2nok($_POST["option"][$option['product_option_id']]["height"]); 
$width = vir2nok($_POST["option"][$option['product_option_id']]["width"]);
Andrii Filenko
  • 954
  • 7
  • 17