passing javascript variable to phpmysql query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yuva17raj
    New Member
    • Dec 2007
    • 19

    passing javascript variable to phpmysql query

    hi

    i need to write a javascript function in which i need to update the record by passing a javascript variable and i have tried in this format but no solution can any one help me for the following

    Code:
    function assigntask(assignedperson,[B]userid[/B])
    {
    alert(userid);
    var test = <? mysql_query("update mytable set assignedto='test454' where id='[B]+userid+'[/B]");?>
    }
    reply me ASAP

    regards
    yuvaraj
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    you might use the XMLHttpRequest-object for this ... the link shows you how to use it ...

    kind regards

    Comment

    • pronerd
      Recognized Expert Contributor
      • Nov 2006
      • 392

      #3
      You can not pass data from JavaScript variables to PHP variables. JavaScript runs on the client and PHP runs on the server. Also since JavaScript is not ruining on the server it can not connect to a database.

      To get your data to the PHP code you need to send it via a GET or POST request, or use AJAX as gits mentioned.

      Comment

      Working...