0

我有一个调用此 URL 的 Java 小程序,该 URL 链接到应该写入文件但...没有骰子的 php 脚本。我收到一个 http 500 错误。有什么线索吗?

http://127.0.0.1/DBoperations.php?operation=write&UserId=james&Score=10

#DBoperations.php
<?php
$operation = $_REQUEST["operation"]
$UserId = $_REQUEST["Userid"];
$Score = $_REQUEST["Score"];

if (operation =="write"){
write();
}
if (operation =="read"){
read();
}

function write()
{
$myFile = "testsroce.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "$UserId - $Score";
fwrite($fh, $stringData);
fclose($fh);
}

function read()
{
$file = new SplFileObject('testscores.txt');
$file->setFlags(SplFileObject::DROP_NEW_LINES);
$match = false;
foreach($file as $line){
if( false !== stripos( $line, $UserId ) ){
    $match = true;
    break;
}
}
if( true === $match ){
echo $file;
} else {
echo "No Match Found";
}
}
?>
4

1 回答 1

0

您在此行之后缺少一个分号:

$operation = $_REQUEST["operation"]

应该

$operation = $_REQUEST["operation"];

您还缺少$一些地方的标志,例如

if (operation =="write"){

应该:

if ($operation =="write"){
于 2012-10-22T19:37:27.407 回答