1 Replies - 282 Views - Last Post: 22 February 2013 - 02:40 AM Rate Topic: -----

#1 leixnt  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 30
  • Joined: 24-July 11

JS & PHP Variable Problem

Posted 22 February 2013 - 01:32 AM

well.. first let see my code below

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd"
    >
<html lang="en">
<head>
    <title><!-- Insert your title here --></title>
<script type="text/javascript"
 src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {

    $('#from').keyup(function(event) {		
		<?php
			$mysql_user="root";
			$mysql_password="";
			$mysql_database="database";	
			$mysql_host="localhost";
			$koneksi_db = mysql_connect($mysql_host, $mysql_user, $mysql_password);
			mysql_select_db($mysql_database, $koneksi_db); 
			$que = "SELECT * FROM `ms_item` WHERE kodeitem = 'B01'";
			
			$q=mysql_query($que);
			$rowC = mysql_fetch_array($q);
			
			$test = $rowC['NameItem'];
		?>
		
		var test = "<?php echo $test; ?>";
		
		
		$('#to').val(test);
    });

  });
</script>
</head>
<body>
<input type="text" id="from" />
<input type="text" id="to" />
</body>
</html>



this code run, but i need to pass javascript variable to php variable to execute query.
see this line:
$que = "SELECT * FROM `ms_item` WHERE kodeitem = 'B01'";

that 'B01' should be from textbox (id: from)

how can to pass/trick that variable?
thanks

Is This A Good Question/Topic? 0
  • +

Replies To: JS & PHP Variable Problem

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3515
  • View blog
  • Posts: 10,140
  • Joined: 08-June 10

Re: JS & PHP Variable Problem

Posted 22 February 2013 - 02:40 AM

you are aware that PHP runs on the server and Java​Script runs on the client?

eventually, that code attempt will never work because of said reason. what you have to do is send an AJAX request to the PHP script on the server and process the returning result.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1