0

I'm trying to make a form where the user can add their own 'questions + answers' to the quiz.

I loaded the original questions from a text file. The added questions will then be processed by process_editadd.php

<?php
session_start();
$file = fopen('data.txt', 'r');
$array=$_SESSION['questions_array'];

//make array out of values
$q=array($_POST['question'],$_POST['one'],$_POST['two'],$_POST['three'],$_POST['four']);
//add to file
$file=fopen("data.txt","w+");
fwrite($file, implode(',', $q)).

header('Location:module.php');

?>

The array adds onto the text file, but the problem is that it replaces the whole thing. I don't want the questions to replace the previous ones, I just want them added. Do you guys know what's wrong with the code?

Note: I'm not allowed using mySQL or Javascript

4

1 に答える 1

1

実際のデータベースを使用するように切り替えると、作業がずっと楽になります... それができない場合は、fputcsvfgetcsvを調べて、面倒な問題を少し減らしてください。

あなたの内破バージョンは現在、CSV インジェクションに対しても脆弱です...あなたが書いているテキストのいずれかにコンマが含まれている可能性があるケースを処理しません。その場合、後でデータを読み戻すときに、余分な「列」があることに突然気付くでしょう。

于 2012-04-22T18:32:12.767 に答える