招呼球員的價值,我有這個問題我不能比較這兩個字符串
<?php
$dir = '/var/www/devData/test';
// create new directory with 777 permissions if it does not exist yet
// owner will be the user/group the PHP script is run under
if (!file_exists($dir)) {
mkdir ($dir, 0777);
}
$flag = 0;
$stringData = $_POST['data']; // echo = null
$file = "/var/www/devData/test/ciao.txt";
$fh = fopen($file, 'a+') or die("can't open file");
while(!feof($fh)) {
$theData = fgets($fh, filesize($file));
array_push($arr,$theData);
$i++;
}
for($j=0; $j<count($arr); $j++)
if($stringData == $arr[j]){ // is the problem
$flag = 1;
}
if($flag = 0){
fwrite($fh, $stringData); // fwrite works perfectly even if i try to print $string the result is null
}
fclose($fh);
?>
有人可以給我解釋一下如何解決這個問題呢?這個腳本的目的是避免用戶編寫兩次同樣的事情
所以我們應該去猜測爲什麼'$ _POST ['data']'未定義?我的猜測:*你的表格有什麼問題。 – phant0m 2012-08-01 10:17:13
不是因爲我可以將$ _POST的內容寫入正常的文件 – Edivad 2012-08-01 10:20:14
我看到這是用'ajax'標記的,您是否將數據作爲文章傳遞?你正在做什麼樣的Ajax請求?你是否在使用像jQuery這樣的庫..這麼多的問題! – Dale 2012-08-01 10:20:31