Passing value from JS to PHP and to SQL?
This is my code where I actually pass the value (variable countForPHP) using XHR:
Here's how I get the value sent from the XHR:
xmlHttp.open("GET", "count.php?r=" + Math.random + "&count=" + countForPHP, async);
Does anyone know how to solve this problem?
$counter = $_GET["count"];
$pdo = new PDO('mysql:host=host;dbname=database;', 'username', 'password');
$sql = "UPDATE tbl_click SET click = click + ($counter)";
I think you might have meant:
Sorry for the lecture but here it is anyway.
The key to writing good code is being easily able to debug said code.
Youve provided yourself with zero means to do so, that means every line of code youll ever write will potentially be a huge chore to make work.
You need to be able to know exactly where the code is breaking down.
ANyway, nothing more from me, best of luck.
Aren't " and ' the same? Maybe my problem is where I add the variable in the SQL Query?
Originally Posted by criterion9
Are you receiving any output from the PHP file in question? I.e., is xmlhttp.responseText empty?
Are you certain your file paths are correct? Remember that with AJAX calls you need to make sure the path of the PHP file is relative to the currently active page, not relative to the file on the server.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)