Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    5
    Thanks
    2
    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.

    Code:
    <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+"");
    ?>
    
    }
    </script>
    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
    New Coder
    Join Date
    Mar 2012
    Posts
    25
    Thanks
    0
    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
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,553
    Thanks
    78
    Thanked 4,382 Times in 4,347 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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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