写入文件和搜索文件php

时间:2012-10-22 19:28:11

标签: php fwrite

我有一个java applet,它调用这个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";
}
}
?>

1 个答案:

答案 0 :(得分:0)

在此行之后您缺少分号:

$operation = $_REQUEST["operation"]

应该是

$operation = $_REQUEST["operation"];

您在一些地方也错过了$标志,例如

if (operation =="write"){

应该是:

if ($operation =="write"){