2012-10-22 107 views
0

我有一个Java小程序,调用这个URL链接到一个PHP脚本,应该写入文件,但没有骰子。我得到一个http 500错误。任何线索?写入文件和搜索文件php

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"; 
} 
} 
?> 
+0

是旨在你的 “读” 和 “写” 的文件名有什么不同? –

+0

@Kolink'testsroce'听起来合法xD – TheZ

+1

你的PHP脚本显示什么错误信息?如果需要,打开错误信息。 –

回答

0

你缺少这行后分号:

$operation = $_REQUEST["operation"] 

应该

$operation = $_REQUEST["operation"]; 

您还缺少一些地方$迹象,例如

if (operation =="write"){ 

应该是:

if ($operation =="write"){ 
+0

哇......好的,谢谢 – UnbrandedTech

+0

另外看看你的'write()'函数。这个语句'$ stringData =“$ UserId - $ Score”;'会出错。您可能必须将'$ UserId'和'$ Score'变量作为参数发送给函数。 – Ryan