mtnmchgrl Posted May 1, 2009 Share Posted May 1, 2009 I am lost on where to start with an assignment. If someone could please direct me on what to do, I would be greatly appreciative. I have two files called registerUsers.html and registerUsers_handler.php. The html form asks the user to register their username and password. Here is my HTML CODE: <form action="registerUsers_handler.php" method = "get" /> <h2>Registration</h2> Please enter your user name: <br /> <input type='text' size='30' name='userName'><br /><br /> Please enter your password: <br /> <input type='text' size='30' name='password'><br /><br /> <input type='submit' value='submit' name='submit'> <input type='reset' name='reset' value='Reset Form'> The PHP form needs to call three functions. checkForNameAndPass($uName, $pass) -- that accepts the username and password checkForExistingUser($fh, $fileName, $user) -- that accepts the file handle, file name, and username addUserAndPass($fh, $user, $pass) -- accepts the file handle, user name, and password This is all i have so far for the code. I have a book but it is TERRIBLE and there are no examples for this there. <?php //Gets and accepts username and password $uName = $_GET['userName']; $pass = $_GET['password']; strlen(trim($uName)); strlen(trim($pass)); chmod($uName); ?> Any help or tips would be appreciated.... Quote Link to comment https://forums.phpfreaks.com/topic/156348-php-newbie-need-help-with-registering-a-user-form/ Share on other sites More sharing options...
ballhogjoni Posted May 1, 2009 Share Posted May 1, 2009 Im not gonna help until you start using a database. j/k fopen should help you Quote Link to comment https://forums.phpfreaks.com/topic/156348-php-newbie-need-help-with-registering-a-user-form/#findComment-823175 Share on other sites More sharing options...
mtnmchgrl Posted May 1, 2009 Author Share Posted May 1, 2009 ha ha, we haven't gotten to the MySql portion of the course yet. I have no database. Quote Link to comment https://forums.phpfreaks.com/topic/156348-php-newbie-need-help-with-registering-a-user-form/#findComment-823180 Share on other sites More sharing options...
mtnmchgrl Posted May 4, 2009 Author Share Posted May 4, 2009 can anyone else help? ??? Quote Link to comment https://forums.phpfreaks.com/topic/156348-php-newbie-need-help-with-registering-a-user-form/#findComment-825922 Share on other sites More sharing options...
premiso Posted May 4, 2009 Share Posted May 4, 2009 Do you know how to make a function? If not read up on them here Functions. Specifically on the ones with parameters. IE: function yourFunctionName($parameter1, $parameter2) { // do something with the parameters } That is a basic example of how it is setup. As suggested look into use the file operators: fopen, fread, fwrite and fclose. Since this is an assignment, I am sorry I cannot just give you the answer, you would not learn much from it. The links I have provided should be more than enough to get you going on the right track to finish your assignment. Quote Link to comment https://forums.phpfreaks.com/topic/156348-php-newbie-need-help-with-registering-a-user-form/#findComment-825929 Share on other sites More sharing options...
mtnmchgrl Posted May 4, 2009 Author Share Posted May 4, 2009 We just had a chapter on Functions, so I know a little. The chapter that covers files and directories (what this assignement is on) does not give anything similar to what is asked. I think you have gotten me on the right track with those and i will read up on the provided links. I definitely don't want to just have the answer but sometimes i spends hours reading my book and scouring the internet and things just don't add up. PHP and me don't always get along. Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/156348-php-newbie-need-help-with-registering-a-user-form/#findComment-825935 Share on other sites More sharing options...
premiso Posted May 4, 2009 Share Posted May 4, 2009 Thanks for your help! No problem. It can be frustrating, but any language is to start with. Once you get the baselines down it is much easier. If you come across a point in the code that you need help with feel free to post it, the main goal is that you try and do it/debug it yourself as when you learn with trial and error, those tend to stick out in your head. Also, if you would like it critiqued/looked over when it is finished, this forum would be a good spot to ask that. Best of luck. Quote Link to comment https://forums.phpfreaks.com/topic/156348-php-newbie-need-help-with-registering-a-user-form/#findComment-825939 Share on other sites More sharing options...
mtnmchgrl Posted May 4, 2009 Author Share Posted May 4, 2009 I forgot to add this....There is a file called users.txt which has a short list of users and passwords. these functions are supposed to allow the user to enter a user name and password, hit submit and then the functions first check to see something has been entered, then checks to see if there are duplicate usernames/pw from the exisiting file and if there are no duplicates it appends it to the end. That being said, can someone look over what I have and tell me if i'm getting warmer? </head> <body> <form action="registerUsers_handler.php" method = "get" /> <h2>Registration</h2> Please enter your user name: <br /> <input type='text' size='30' name='userName'><br /><br /> Please enter your password: <br /> <input type='text' size='30' name='password'><br /><br /> <input type='submit' value='submit' name='submit'> <input type='reset' name='reset' value='Reset Form'> </body> </html> PHP <?php function checkForNameAndPass ($uName, $pass) { //$filename = "users.txt"; $uName = $_GET['userName']; $pass = $_GET['password']; $fh = open("users.txt", 'r'); strlen(trim($uName)); strlen(trim($pass)); if(checkForNameAndPass($uName, $pass) == TRUE){ } echo "It works!"; if (checkForExistingUser($uName, $fh)){ //if true: user exist //kick out error msg. }else { //close exisiting file handle } $fh = open("users.txt", 'a'); if (addUserAndPass ($fh, $user, $pass)) { echo "User added"; else { } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/156348-php-newbie-need-help-with-registering-a-user-form/#findComment-826158 Share on other sites More sharing options...
premiso Posted May 4, 2009 Share Posted May 4, 2009 Kind of, not really. You do a strlen with $uName and $pass, but you are not checking it or using it in an If statement anywhere. strlen returns the length of the string. Also you are passing $uName and $pass as parameters, why are you setting them to get inside the function? Third, you are calling checkForNameAndPass within itself and in an if statement. It will never return a value and as such will cause an infinite loop when called. Forth the $fh is equaled to open, it should be fopen. As for the checking I would use file to read in the current file if it is allowed, as that would put each line into an array and allow you to loop through it testing if the username/password combination is there. Some advice, I think you need to pay more attention to your brackets, as the "echo "It Works" line is outside of that if, so no matter what it will echo the it works line, and no action is being done inside that if. The function, checkfornames... I do not see where the function ends (no ending bracket). Well hope that helps you a bit more. Quote Link to comment https://forums.phpfreaks.com/topic/156348-php-newbie-need-help-with-registering-a-user-form/#findComment-826165 Share on other sites More sharing options...
mtnmchgrl Posted May 4, 2009 Author Share Posted May 4, 2009 Man.......that was even after i got help from my teacher. ok i'll keep trying. Quote Link to comment https://forums.phpfreaks.com/topic/156348-php-newbie-need-help-with-registering-a-user-form/#findComment-826197 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.