2012-10-22 129 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