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 回答