0

I need to pass the PHP retrieved value from database to Ajax function for further querying in database my code is given below.

The PHP Script:

$query = mysql_query("SELECT * FROM employee") or die(mysql_error());

while($res=mysql_fetch_assoc($query)){  
echo $res['emp_id'];   
$emp_id=$res['emp_id']

and submit button with id name-submit

The Javascript

$('input#name-submit').on('click',function(){ 
var empid = $('php echo $emp_id; ');
alert(empid);

the script is running just below the php script.

5
  • you never opened a PHP tag, so how would your server know it's supposed to do some php'ing? If you look at your source code, you'll notice it's just printing the letters you wrote. Commented Sep 17, 2012 at 20:28
  • 2
    Where do all of you new guys come here from using mysql_query? I wanna send a message to whoever is teaching you this to update his instructions and teach you to use PDO instead. Commented Sep 17, 2012 at 20:29
  • 3
    @xception Then send a message to internet. Google mysql php tutorial and you'll be surprised. Commented Sep 17, 2012 at 20:31
  • 1
    I see, so google is the one to blame :P Commented Sep 17, 2012 at 20:34
  • done bt the in alret box im having [object object] which means it is in array now how cld i xtract the value from it :X help plz Commented Sep 17, 2012 at 20:49

1 Answer 1

4

Exactly as you are doing, but by putting the full opening tag in there. Change the second JS line to:

var empid = $('<?php echo $emp_id; ?>');
Sign up to request clarification or add additional context in comments.

1 Comment

josh acctually iwasnt ablt to print the php tag here thats y and thanx thing is done but thats was not the problem the main issue i was facing was using old version of jquery library nyway thanx but got new issue in alret box im having undefined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.