0
<script type='text/javascript'>

function calculate(){
  
  
  var text2answer = document.getElementById('Text2').value;
  var answer=$quarity-text2answer;
  
  
  alert( answer);

  $sql= 'UPDATE `receved items` SET Quantity=answer where id=18';
  echo $sql;
  
}

</script>"; 

I'm trying to update mysqli database inside JavaScript I have variable that calculated from textbox and get answer I want that answer from variable to update to mysql database please help

queen nana
  • 83
  • 5
  • 2
    You seem to be mixing JavaScript and PHP in the same function. That can't work. JavaScript runs on the client, PHP runs on the server. You need to use AJAX to send a request to the server so it can update the DB. – Barmar May 11 '22 at 16:48
  • 1
    i tried node update but didn't work https://www.w3schools.com/nodejs/nodejs_mysql_update.asp https://www.mysqltutorial.org/mysql-nodejs/update/ please can you help? with my above code – queen nana May 11 '22 at 16:55
  • 2
    If you're using PHP on the server, `node.js` is irrelevant. – Barmar May 11 '22 at 16:57

0 Answers0