I’d like to know how can I use a jquery variable in a sql query?
Here is my jquery that is in my php file:
?>
<script type="text/javascript">
jQuery.noConflict();
jQuery(function(){
jQuery('#event_form_field-<?php echo $event_id; ?>').click(function() {
var bradio = jQuery("input[type=radio]:checked").val();
alert(bradio);
}) });</script> <?php
I want to use the bradio variable in a sql query (on the Having clause, for example Having answer=’$bradio’.
But i don’t know how to passe the jquery variable in php.
Can you please explain me how can I do this?
Thanks.
You can use AJAX to pass the variable to a PHP script. That PHP script can also return data to the JavaScript AJAX call, for instance you can output
errororsuccessin your PHP file so the JavaScript code can alert the user as to what happened (in my example this response is saved in theserverResponsevariable):Some documentation:
$.get(): http://api.jquery.com/jquery.get