MacroHawk Posted June 30, 2007 Share Posted June 30, 2007 How would I make form with 2 text boxes 1 is username and 2 is password and 1 button that when you click it, it will save the username anf password into 2 speract text files. Break down: A register program. Writes the username in 1 text (user.txt) and password in another (pass.txt) If some one could do this for me I would be so greatful! Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/ Share on other sites More sharing options...
Barand Posted July 1, 2007 Share Posted July 1, 2007 Why do you need 2 speract text files? Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-286925 Share on other sites More sharing options...
MacroHawk Posted July 1, 2007 Author Share Posted July 1, 2007 I am making a program in VB6 and it as an Auth system. And it reads the user name and password from the 2 separt txt files. Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-286926 Share on other sites More sharing options...
MacroHawk Posted July 1, 2007 Author Share Posted July 1, 2007 still unsolved... Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-286998 Share on other sites More sharing options...
pocobueno1388 Posted July 1, 2007 Share Posted July 1, 2007 I see what Barand is saying, why have two separate text files?  Just format your text file like this: Username || Password  Thats all you need. Then you will have the users username and password right there in the same file. Then when you want to check if they have the correct login information, you just have to explode the line by the "||" and check if there is a match.       Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-287000 Share on other sites More sharing options...
MacroHawk Posted July 1, 2007 Author Share Posted July 1, 2007 I see what Barand is saying, why have two separate text files?  Just format your text file like this: Username || Password  Thats all you need. Then you will have the users username and password right there in the same file. Then when you want to check if they have the correct login information, you just have to explode the line by the "||" and check if there is a match.  No. There is 2 textboxs 1 for the user name and 1 for the password. When a person clicks submit it will save the contense of the user name field into user.txt and the contense of the password field in pass.txt Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-287009 Share on other sites More sharing options...
pocobueno1388 Posted July 1, 2007 Share Posted July 1, 2007 Yes, I understand what you are saying. Why not just save both text box values to the same text file as I explained?  If you use two text files, it is going to be hard to figure out which username goes with which password. Plus there is just no need for it when you can get the same thing accomplished with one text file.  Here is a tutorial for how to write text to a file: http://php.about.com/od/advancedphp/ss/file_write_php.htm  Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-287012 Share on other sites More sharing options...
MacroHawk Posted July 1, 2007 Author Share Posted July 1, 2007 ya but I need it in to for my application. Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-287014 Share on other sites More sharing options...
pocobueno1388 Posted July 1, 2007 Share Posted July 1, 2007 If you want it that way, then thats fine. Â First try to do it yourself by using the tutorial, if that fails, then post the code to your form so we can help direct you. Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-287016 Share on other sites More sharing options...
MacroHawk Posted July 1, 2007 Author Share Posted July 1, 2007 I read it but it is not exactly what I needed... I need a input form with 2 text boxes and 1 submit button. Srry if i sound rud I am good a lots of programing but just never realy used php Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-287018 Share on other sites More sharing options...
pocobueno1388 Posted July 1, 2007 Share Posted July 1, 2007 Well, of course the tutorial isn't exactly matching your need, but it isn't difficult to implement your plan into it. Â Post the code to your form, I will help you through it. Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-287022 Share on other sites More sharing options...
MacroHawk Posted July 1, 2007 Author Share Posted July 1, 2007 I don't really no how I would make one... I'm an expert in vb but I don't know why i can get this... Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-287032 Share on other sites More sharing options...
pocobueno1388 Posted July 1, 2007 Share Posted July 1, 2007 Here you are:  <?php if ($_POST['submit']) {     if (isset($_POST['username']) && isset($_POST['password'])) {     //Write the username to the user.txt file     $File = "user.txt";     $Handle = fopen($File, 'a');     $Data = "{$_POST['username']}\n";     fwrite($Handle, $Data);     fclose($Handle);         //write the password to the pass.txt file     $File = "pass.txt";     $Handle = fopen($File, 'a');     $Data = "{$_POST['password']}\n";     fwrite($Handle, $Data);     fclose($Handle);         print "Data Written<p>";       } else {     echo "You left something blank, please fill both fields in.<p>";   }   } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> Username: <input type="text" name="username"><br> Password: <input type="text" name="password"><br> <input type="submit" name="submit" value="Submit"> </form>  Remember to save this as a .php file. Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-287045 Share on other sites More sharing options...
MacroHawk Posted July 1, 2007 Author Share Posted July 1, 2007 OMFG! Thank You So Much! It WORKED! But I still have 1 more tiny question? How can i make it so that if that user name is all ready in the user.txt it will not reg them? Thanx so much! Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-287052 Share on other sites More sharing options...
pocobueno1388 Posted July 1, 2007 Share Posted July 1, 2007 <?php if ($_POST['submit']) {     if (isset($_POST['username']) && isset($_POST['password'])) {         $username = trim($_POST['username']);     $pass = trim($_POST['password']);         //Write the username to the user.txt file         $lines = file('user.txt');         foreach($lines as $line){       $line = trim($line);             if ($line == $username) {         echo "The username you chose already exists!";         exit;       }     }         $File = "user.txt";     $Handle = fopen($File, 'a');     $Data = "$username\n";     fwrite($Handle, $Data);     fclose($Handle);         //write the password to the pass.txt file     $File = "pass.txt";     $Handle = fopen($File, 'a');     $Data = "$pass\n";     fwrite($Handle, $Data);     fclose($Handle);         print "Data Written<p>";       } else {     echo "You left something blank, please fill both fields in.<p>";   }   } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> Username: <input type="text" name="username"><br> Password: <input type="text" name="password"><br> <input type="submit" name="submit" value="Submit"> </form> Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-287247 Share on other sites More sharing options...
MacroHawk Posted July 1, 2007 Author Share Posted July 1, 2007 It does not work...?   :'( Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-287337 Share on other sites More sharing options...
pocobueno1388 Posted July 1, 2007 Share Posted July 1, 2007 Really? I tested it on my own server and it worked fine. What exactly isn't working about it? Just the part that checks if the username already exists or not? Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-287339 Share on other sites More sharing options...
MacroHawk Posted July 1, 2007 Author Share Posted July 1, 2007 Actualy... It sorta does and sorta doesn't... To make it so that people can't view the text I CHMOD it to 662. And when I do that then the check if the user name is all ready there does not work... But when I take off the CHMOD so that every one can view it does work... But I need it so that people can't view? Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-287340 Share on other sites More sharing options...
Barand Posted July 1, 2007 Share Posted July 1, 2007 Put text files in a folder outside the web root Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-287343 Share on other sites More sharing options...
MacroHawk Posted July 1, 2007 Author Share Posted July 1, 2007 It worked Thank You! Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-287390 Share on other sites More sharing options...
pocobueno1388 Posted July 1, 2007 Share Posted July 1, 2007 Don't forget to mark the topic as solved Link to comment https://forums.phpfreaks.com/topic/57902-saving-to-text-file/#findComment-287394 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.