2012-10-22 3 views
0

나는 파일을 쓰지 말고 주사위를 쓰지 않는 PHP 스크립트에 링크하는이 URL을 호출하는 자바 애플릿을 가지고 있습니다. HTTP 500 오류가 발생합니다. 어떤 단서?파일에 쓰기 및 파일 검색 PHP

$operation = $_REQUEST["operation"] 

당신은 또한, 예를 들어, 몇 군데에 $ 기호 누락

$operation = $_REQUEST["operation"]; 

해야합니다

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

이 줄 뒤에 세미콜론 누락

if (operation =="write"){ 

은 다음과 같아야합니다

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

와우 ... 감사합니다. – UnbrandedTech

+0

또한'write()'함수를 살펴보십시오. 이 문장'$ stringData = "$ UserId - $ Score";'는 에러가 발생합니다. 함수에 매개 변수로'$ UserId'와'$ Score' 변수를 보내야 할 수도 있습니다. – Ryan