you could use a $_SESSION variable instead of file > $filename = "addusers.txt"; > if (isset($users)) { > $temp = $_POST['users']; > $handle = fopen("$filename", "w+"); > fwrite($handle, $temp); > > $users = file("$filename"); > if (ereg("\t", $users[0]) == true) $separator = "\t"; // om texten är
if(isset($_POST['users'])
{
$_SESSION['temp_users'] = $_POST['users'];
}
if (ereg("\t", $_SESSION['temp_users'][0]) == true) $separator = "\t"; .......etc
hope it helps Pete
ØYstein HåLand wrote:
I want to give the visitor a possibility to create plenty of new user accounts by letting the him paste the userinfo from a tab-, comma- or semicolonseparated file to a textarea (form.php). Then some checking needs to be done (check_users.php) before the final result is written to the db (add_users.php). Right now I'm trying to achieve this by putting the user input into a (temporary) file and populate the fields in check_users.php from this file. This works. But now I will do some changes before I write to the db, and here I know nada. Is there some useful functions here that is useful? (How can I edit this temp-file?) I have (as mentioned above) another idea: use a temporay table and populate this from the user input. Do the changes here, using the queries needed, write from this table to the real place and then drop this table. What is the best approach?
Here is form.php: <?php echo " <HTML> <BODY> <H1>Klistra in från din textfil</H1> Kom ihåg att texten måste vara tabb-, komma- eller semikolonavgränsad <FORM METHOD=POST ACTION=\"check_users.php\"> <TEXTAREA NAME=\"users\" ROWS=\"10\" COLS=\"50\"></TEXTAREA><BR> <INPUT TYPE=\"submit\" VALUE=\"Skicka\"> </FORM> </BODY> </HTML> "; ?>
and here check.users.php (right now) <?php include("../recycle/head.php"); echo " </HEAD> <BODY STYLE=\"background-color:#444444\"> <CENTER><TABLE> <TH COLSPAN=6>Förhandsgranska</TH>
<TR><TD></TD><TD>Förnamn</TD><TD>Efternamn</TD><TD>Klass/grupp</TD><TD>Använ darnamn</TD><TD></TD></TR> "; if ($users == "" || $users == "\r\n") { echo " <SCRIPT LANGUAGE=\"JavaScript\"> <!-- document.write(void(history.go(-1))) //--> </SCRIPT>"; } $filename = "addusers.txt"; if (isset($users)) { $temp = $_POST['users']; $handle = fopen("$filename", "w+"); fwrite($handle, $temp);
$users = file("$filename"); if (ereg("\t", $users[0]) == true) $separator = "\t"; // om texten är tabbavgränsad else if (ereg(",", $users[0]) == true) $separator = ","; // om texten är kommaavgränsad else $separator = ";"; // om texten är semikolonavgränsad $count = 0; foreach ($users as $v) { list($firstname, $lastname, $mygroup, $username, $password) = explode($separator, trim($v)); $firstname = ucfirst(trim($firstname)); $lastname = ucfirst(trim($lastname)); $mygroup = strtoupper(trim($mygroup)); $username = trim($username); $password = trim($password); echo "<FORM NAME=\"form_$count\" METHOD=POST ACTION=\"{$_SERVER['PHP_SELF']}\"><TR>"; echo "<TD>$count<INPUT TYPE=HIDDEN NAME=\"counter\" VALUE=\"$count\"></TD>"; echo "<TD><INPUT TYPE=TEXT NAME=\"firstname\" SIZE=15 VALUE=\"$firstname\"></TD>"; echo "<TD><INPUT TYPE=TEXT NAME=\"lastname\" SIZE=15 VALUE=\"$lastname\"></TD>"; echo "<TD><INPUT TYPE=TEXT NAME=\"mygroup\" SIZE=7 VALUE=\"$mygroup\"></TD>"; echo "<TD><INPUT TYPE=TEXT NAME=\"username\" SIZE=15 VALUE=\"$username\"></TD>"; echo "<INPUT TYPE=HIDDEN NAME=\"password\" VALUE=\"$password\">"; echo "<TD ALIGN=LEFT><A HREF=\"#\" TITLE=\"Ta bort denna post\" onClick=\"\"><IMG SRC=\"delete.gif\" BORDER=0></A></TD>";//I'm not sure what to do here echo "</TR></FORM>"; $count++; } echo "<FORM NAME=\"show_users\" METHOD=POST ACTION=\"add_users.php\"><TR><TD COLSPAN=6 ALIGN=RIGHT><INPUT TYPE=\"submit\" VALUE=\"OK, skicka\"></TD></TR><INPUT TYPE=HIDDEN NAME=\"temp\" VALUE=\"$temp\"></FORM>"; } echo " </TABLE></CENTER> </BODY> </HTML> "; fclose($handle); ?>
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php