Ache Posted November 23, 2008 Share Posted November 23, 2008 I have a csv file with some user data seperated by comma's that looks like:UserID,Points,Nickname,Firstname,LastnameWhat I want is to add Points to a users account (data) if (s)he has won a random price.prk is the UserID that is send from a form if the user clicks a certain button.What I can't get to work is the part where it should add the Points won by the user.Everything else is working fine. <?php include("config.php");$prk = $_POST['prk']; $tt = rand(0,100); $fh = fopen($dataLog, 'a') or die("can't open file"); $IP = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"]; // Check if a user has won credits if ($tt < (100 / $winkans)) { // Tell the user (s)he has won credits echo ('Gefeliciteerd. U heeft gewonnen'); $msg = " Submitted on $date at $time. From $IP\n"; fwrite($fh, $prk); fwrite($fh, $msg); // Add credits to user account $target = 'out.txt'; $sh = fopen($dataUsers, 'r'); $th = fopen($target, 'w'); while (!feof($sh)) { $tempData = fgetcsv($sh,","); if ($tempData[0] == $prk) { $tempData[1] = $tempData[1]++; fputcsv($th,$tempData); } else { fputcsv($th,$tempData); } } fclose($sh); fclose($th); // delete old source file unlink($dataUsers); // rename target file to source file rename($target, $dataUsers); }// Add entry in log file if someone has clicked but not has won else { // Tell the user (s)he has not won credits $msg = "AAA000 Submitted on $date at $time. From $IP\n"; fwrite ($fh, $msg); echo('Helaas, deze keer heeft u geen credits gwonnen'); } fclose($fh);?></body> Link to comment Share on other sites More sharing options...
Ache Posted November 25, 2008 Author Share Posted November 25, 2008 I changed$tempData[1] = $tempData[1]++;to $tempData[1] = $tempData[1] +1;and now the credits are awarded, but now I am getting"Warning: fputcsv() expects parameter 2 to be array" in this linefputcsv($th,$tempData);I checked the csv file and the error seem to happen when all data has been read/written.How to solve it? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.