This is my first week using php, so thanks in advance for your constructive response.
I have a html page that has a url parameter appended: mywebsite.com/f.html?survey_id=5d86055f35bf41f3a35f2c779fc478dc
I need to pass this survey_id parameter to a php script that saves this id in a text file. My current code is not passing correctly as the textfile is empty.
The html page is /f.html The php script is /test.php
This is all being run server-side.
The saving script works, as if instead of $id I just save a string like 'd', everything works properly.
I have tried the below code using $_GET, but the output is empty so I am assuming that the parameter is not being passed to the .php script which is what executes the fwrite.
I have also read that this can potentially be fixed by modifying the .htaccess file, and tried adding the below to my .htaccess file but it did not solve the problem.
RewriteRule "/pages/(.+)" "/page.php?page=$1" [QSA]
I feel this is not exactly the right rule but do not know how to modify it to fit my particular case.
jQuery(document).on('click', 'div#download', function () {
jQuery('div#counter1').html('Loading...');
var ajax = jQuery.ajax({
method: 'get',
url: '/test.php', // Link to this page
data: { 'increase': '1' }
});
ajax.done(function (data) {
jQuery('div#counter1').html(data);
});
ajax.fail(function (data) {
alert('ajax fail : url of ajax request is not reachable');
});
});
test.php
$myFile = "testFile2.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$id = $_GET['survey_id'];
$stringData = $id;
fwrite($fh, $stringData);
fclose($fh);
The expected result in the text file should be 5d86055f35bf41f3a35f2c779fc478dc.
The current result is that the text file is empty.