I use Javascript to get 'member_id' url parameter and need to then assign that value to a PHP variable that I use in an SQL Query. When I simply echo the PHP variable, everything looks good but if I try to include the PHP variable in the SQL query that I submit via POST, I get an error with the SQL Query.
<script>
var param1var = getQueryVariable("member_id");
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
alert('Query Variable ' + variable + ' not found');
}
</script>
<?php $foo="<script type='text/javascript'>
document.write(getQueryVariable('member_id'));
</script>";
?>
SQL Error: *You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'text/javascript'> document.write(getQueryVariable('member_id')); ')' at line 1*