-1

I have input and I want to get the input value and use it in mysql query as where condition within javascript script Like this:

<script>
function get_total_value_row()
{
<?php 
$products_sql=mysql_query('select * from product where product_name=a');
$products_row=mysql_fetch_object($products_sql);
?>
</script>

What is the correct value which I should replace it with (a) in where condition to work the javascript script?

  • 1
    Possible duplicate of [Send data from javascript to a mysql database](https://stackoverflow.com/questions/8412505/send-data-from-javascript-to-a-mysql-database) – Victor Jun 09 '19 at 17:40
  • This makes no sense. Some of those functions look like (out of date versions of) PHP functions. Do you understand the difference between PHP and JavaScript? If you want to send information from your browser to the database you must first send a HTTP request to the server, either by submitting a form or making an AJAX request via JavaScript code. That request would be received by a PHP script (or other server side language) and the information sent would be used to create the SQL query. The results would then be sent back to the browser in the response. – ADyson Jun 09 '19 at 21:09
  • It looks like you need to learn some basic concepts before you go any further, including the differences between JavaScript and PHP. And also make sure you are using recent study material which does not use out of date, insecure functions such as `mysql_query` – ADyson Jun 09 '19 at 21:10

1 Answers1

2

JavaScript, as defined in your question, can't directly work with MySql. This is because it isn't running on the same computer.

JavaScript runs on the client side (in the browser), and databases usually exist on the server side. You'll probably need to use an intermediate server-side language (like PHP, Java, .Net, or a server-side JavaScript stack like Node.js) to do the query.

Reference: Send data from javascript to a mysql database

Ikelie Cyril
  • 130
  • 7