I made a mistake when I submitted the topic. The variable in the $_POST(......) should have been "data" not "d" but it still has the same error. I didn't submit the code correctly I hope this is better . I am using $_POST as the string that gets passed can be quite long, up to 56 names.
This is a correct submission of the "TestProgram.php"
<!DOCTYPE html>
<html>
<head>
<title>Test program</title>
<script language="javascript">
function formatOutput() {
// lots of formatting goes on here
var formattedText = "This is a test"; //test data
getGame(formattedText);
}
function getGame(str){
//Sends data to the php process "save Game".
var data = "Test String";
var xhr = new XMLHttpRequest();
xhr.open("POST", "saveGame.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (this.readyState === 4 ){
alert(xhr.responseText);
}
};
xhr.send(data);
}
</script>
</head>
<body>
<table width="1000" align="center" border="0">
<br />
<tr>
<td width="500"align="center" colspan="3" <button onclick="formatOutput()"/>Click on me</td>
</tr>
</table>
</body>
</html>
This is then supposed to pass the data to the "saveGame.php
<!DOCTYPE html>
<html>
<body>
<?php
$outputString = $_POST["data"];
$fp = fopen("C:\\xampp\\htdocs\\BowlsClub\\GamesSaved\\test26.txt","w");
if (!$fp){
$message = "Error writing to file. Try again later!" ;
}else{
fwrite($fp, $outputString);
$message = "File saved!";
}
fclose($fp);
echo $message;
?>
</body>
</html>
The error occurs at line 6 ($outputString = $_POST["data"];) . It states that "data" is an 'undefined array key'. Screen shot of error attached.
Is it possible to edit a topic once it's been submitted. I couldn't find any help on it.
jjack46