Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Thanked 0 Times in 0 Posts

    Javascript Variables in mysql_query

    Hey guys, basically what I'm trying to do is display a form, and when a user updates the textbox, it'll automatically query the database to update it. Might save some time then pressing submit over and over again, why not try it.

    <script type="text/javascript">
    function submitform(id,fieldname,formname) {
    var newfield = document.forms[formname].elements[fieldname].value;
    mysql_query("UPDATE pilots SET; "?> +fieldname+ <? " = "; ?> +newfield <?" WHERE id = ";?> +id+"");
    I'm not sure if this idea is possible, but I want to see if maybe I just have invalid syntax in the mysql_query.

  2. #2
    New Coder
    Join Date
    Mar 2012
    Thanked 3 Times in 3 Posts
    Hey guys, basically what I'm trying to do
    Basically, you are trying in completely wrong way. Your code for accessing mysql seems to be for PHP processor on server side, which is executed before page is sent to user. JavaScript is executed after the page is received and very far away from server, on client machine.

    Obviously you could not toss them both.

    You should work with normal $_GET variable in your php form but combine the page which displays form with the PHP script which does processing of form submission.

  3. #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,947 Times in 4,908 Posts
    You could do something like this with AJAX, but your PHP code is utterly bogus, just to start with.

    And you certainly can *NEVER* use JS variables in the middle of PHP code, as Rodion said.
    Be yourself. No one else is as qualified.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts