-1

i have php code like this

<?php
        $queryitemkits="select item_id, cost_price, unit_price from items where item_id='JAVASCRIPTVARIABLE'";


        $resultqueryitemkit = mysql_query($queryitemkits) or die('Query failed item kits!'); 
        while($rowitem = mysql_fetch_assoc($resultqueryitemkit))
                    { 
                        $itemcostprice=$rowitem['cost_price'];
                        $itemunitprice=$rowitem['unit_price'];
                    }
?>

and i have javascript variable named ui.item.value

how to insert that ui.item.value javascript variable to replace JAVASCRIPTVARIABLE in above PHP code?

Devisy
  • 159
  • 3
  • 12
  • 10
    **Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).** They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). **Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement)** instead, and **use [PDO](http://us1.php.net/pdo).** You can POST JavaScript variables to your PHP script, perhaps using AJAX. – Jay Blanchard Jan 15 '15 at 19:07
  • You cannot do this the way you want it. PHP is parsed on the server, before the document is served to the client. The JavaScript is parsed on the client, after the PHP input is generated. You need a get, form or ajax call to pass a variable to PHP from the client. – Mouser Jan 15 '15 at 19:14
  • 1
    PLEASE DON'T DO THIS. Code like this can cause SQL injection attacks on your website. Always use prepared statements. – mohkhan Jan 15 '15 at 19:16

1 Answers1

1

Remember PHP is on the server, and the variable "JAVASCRIPTVARIABLE" in the client, you need to submit the variable to the server, also you need input validation, JAVASCRIPTVARIABLE it can be empty when is received on the server.

rescobar
  • 1,261
  • 15
  • 25