View Full Version : Javascript Variables in mysql_query

07-24-2012, 07:45 AM
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.

07-24-2012, 12:50 PM
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.

Old Pedant
07-24-2012, 09:15 PM
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.