0

What I want is perform some addition of values on dynamic input fields but its showing variable not found. Here is my form input field

<input type="text" name="test[]" placeholder="test" onchange=calculate();>

my javascript function

function calculate() {
    var test = <?php echo json_encode($test); ?>;
    alert(test);
    console.log(test);
}

and I have a save.php file which insert data to MySQL

foreach($_POST['name'] as $key => $val) {
    $proj = $_POST['project'][$key];
    $test = $_POST['test'][$key];
    $insert = "INSERT INTO test (name,project,test) values ('$val','$proj', '$test')";
    $result = $conn->query($insert);
}
Alishah momin
  • 114
  • 1
  • 10
  • **Warning: You are wide open to [SQL Injections](http://php.net/manual/en/security.database.sql-injection.php)** and should really use [Prepared Statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) instead of concatenating your queries. Specially since you're not escaping the user inputs at all! – M. Eriksson May 05 '18 at 09:44
  • I know @MagnusEriksson I was just trying it with simple query. – Alishah momin May 05 '18 at 12:46
  • Is there any way I can get data of dynamically created inputs in javascript and perform calculations? – Alishah momin May 05 '18 at 12:47

0 Answers0