Jump to content
Larry Ullman's Book Forums

AprilSwenby

Members
  • Posts

    85
  • Joined

  • Last visited

Everything posted by AprilSwenby

  1. I am looking into the second call of the function - and I know I'm onto something - but it's still not working. I just don't think I'm completely comprehending the way this function works with the text file. $newdata = file_get_contents($file); //Reads the file contents $data = file_get_contents($file); //Reads the file contents $tok = strtok($data, " ");//First call of the strtok function which is putting the data contents into one string while ($tok != false) // This is supposed to take everything that was separted as tokens from the data file { $tok = strtok(" "); } if ($_POST['username'] == $tok ) { // compares the indivdual words from the $data file to the what the user entered in the username box and initiates the second call. $problem = TRUE; print '<p>That username has been taken, please try again</p>'; }
  2. Please note that I do understand that the needs to be a second call to the strtok() function. But I don't understand that language. Can you find a way to re-word that for me? I am finding that the first strtok() call uses the string argument. After the first call, this function only needs the split argument, as it keeps track of where it is in the current string. To tokenize a new string, call strtok() with the string argument again I don't know "how" to do that... If I apply this line if ($_POST['username'] == strtok($data) ) That really doesn't do anything but repeat the line above it.
  3. I re-read the user manual - and I am going to have you look at my comments - Apparently, my data isn't separated. What function am I missing to call? $newdata = file_get_contents($file); //Reads the file contents $data = file_get_contents($file); //Reads the file contents $data = strtok($data, " ");//separates the contents of the $data into tokens - the content that needs separating is the $data and the token is the space which is found in " ". Now - $data should be separated data if ($_POST['username'] == $data) { // compares the individual words from the $data file because they are now separated into tokens to the what the user entered in the username box $problem = TRUE; print '<p>That username has been taken, please try again</p>'; }
  4. I have looked at the manual - and but the context used "isn't in English" to me yet. I have a tough time translating their context.... But I'll keep plugging away - at least I know I'm on the right track. The strtok() function was explained about 4 chapters back - but when I was re-reading the book - that's when I came across it again and thought it might be a good fit for this purpose. However, the getcsv() function was described in this chapter and after I read about it in the manual - I thought that one might work too. I needed to find a function and stick with it....but I didn't know which to choose! I will take your recommendation and stick with the strtok() function and work from there.... I needed a little affirmation that I was using the correct function - thanks. I'll keep pluging away and get back to you...
  5. well - the other function I was toying with was this... Although that isn't producing the outcome the author wanted either. Is this the other way you were referring to? while($line = fgetcsv($newdata, 10000, " ") ) { if ($_POST['username'] == $newdata) { // compares the indivdual words from the $data file to the what the user entered in the username box $problem = TRUE; break; } fclose($fp); print '<p>That username has been taken, please try again</p>';
  6. Here is what it returned... April 2a2d595e6ed9a0b24f027f2b63b134d6 1321586320291 Aaron 098f6bcd4621d373cade4e832627b4f6 13215878883365 Tammy daffd55e1b8020c7a60a7b6e36afb775 13215880821420 Tammy daffd55e1b8020c7a60a7b6e36afb775 13215882131973 That is the contents of my text file. What exactly am I looking for? What should it echo?
  7. I even tried this line of code instead.... $data = file_get_contents($file); //Reads the file contents $data = strtok($data, " "); while ($_POST['username'] == $data) { print '<p>That username has been taken, please try again</p>'; } But at any rate, I think I didn't have an statement closed - and the code is functional now - but it is not producing the error message when I enter a duplicate name.... if (is_writable($file)) { // Open the file. $data = file_get_contents($file); //Reads the file contents $data = strtok($data, " ");//separates the contents of the $data into individual words if ($_POST['username'] == $data) { // compares the indivdual words from the $data file to the what the user entered in the username box $problem = TRUE; print '<p>That username has been taken, please try again</p>'; }
  8. When I echo the variable, I still get the same page - nothing echos back to me. only the word register which is my heading.
  9. Hi there.... After I thought about quitting my class - I wasn't happy with myself! I decided to go back to square one - and read the book - and I got to Chapter 6 - where it talks about the control structures and I did find out where my hang up was.... Then I also came across this function - and I just know I'm onto something... But when I run this script - the only thing that is printed is Register.... which is my html h1 tags. So none of my php is coming through.... Dreamweaver isn't showing me that I have any syntax errors.... $data = file_get_contents($file); //Reads the file contents $data = strtok($data); if ($_POST['username'] == $data) { print '<p>That username has been taken, please try again</p>';
  10. I did try this too - and that seems like it might be more what you are thinking, $file = explode( ' ' , '$data'); But I got an error. Warning: file_put_contents() expects parameter 1 to be string
  11. are you referring to the trim function... something like this? $data = file_get_contents($file); //Reads the file contents if ($_POST['username'] != trim('$data')) { $problem = TRUE; print '<p class="error">That username has been taken</p>'; }
  12. This is what what echoed back to me... Looks like the usernames and the encrypted passwords times 2. Register sandy 2a2d595e6ed9a0b24f027f2b63b134d6 13214921493233 sandy 2a2d595e6ed9a0b24f027f2b63b134d6 13214925052444 April 2a2d595e6ed9a0b24f027f2b63b134d6 13214925133957 Brent 2a2d595e6ed9a0b24f027f2b63b134d6 13214925213887 Lexi 2a2d595e6ed9a0b24f027f2b63b134d6 1321492609494 Noah 2a2d595e6ed9a0b24f027f2b63b134d6 1321492640686 Aubree 2a2d595e6ed9a0b24f027f2b63b134d6 13214927182237 Ally 2a2d595e6ed9a0b24f027f2b63b134d6 1321492764580 austin 2a2d595e6ed9a0b24f027f2b63b134d6 13214959482343 Dad 657f8b8da628ef83cf69101b6817150a 13214973592546 mom 716f6b30598ba30945d84485e61c1027 13214974674171 Jim 098f6bcd4621d373cade4e832627b4f6 1321502406245 Jason 098f6bcd4621d373cade4e832627b4f6 13215024281741 sister 5f4dcc3b5aa765d61d8327deb882cf99 13215025103858 sister 098f6bcd4621d373cade4e832627b4f6 13215025541571 You are now registered!
  13. I did this and my file still doesn't work, but I suspect that I now need to work on the if statement line? I know that if ($_POST['username'] is correct. I am not sure about the rest - $data = file_get_contents($file); //Reads the file contents if ($_POST['username'] != '$data') { $problem = TRUE; print '<p class="error">That username has been taken</p>'; }
  14. and I tried this: $file = file_get_contents('../users/'); //Reads the file contents if ($_POST['username'] == '$file') { $problem = TRUE; print '<p class="error">That username has been taken</p>'; }
  15. This must be somewhat the same thing as what I was trying - because it didn't work... $file = file_get_contents('$mydata'); //Reads the file contents if ($_POST['username'] == '$mydata') { $problem = TRUE; print '<p class="error">That username has been taken</p>'; }
  16. I'm sorry - I understand what you are saying - and if I saw the code, I would understand it... I just can't write it! I have no idea where to even start! Can you give me any other clues? It's not that you're not great at explaining things... It's just that I don't know how to put what I want it to do in the syntax that is understood by the server!
  17. $file = $mydata; if ($_POST['username'] == '$mydata') { $problem = TRUE; print '<p class="error">That username has been taken</p>';
  18. I've been trying a few more things - and this is my latest... Am I close? file_get_contents('$file'); //Reads the file contents $file = $mydata; if ($_POST['username'] == ('$mydata')) { $problem = TRUE; print '<p class="error">That username has been taken</p>'; }
  19. This didn't work either: file_get_contents('$file'); //Reads the file contents if ($_POST['username'] == $_POST[$dir . 'users.txt']) { $problem = TRUE; print '<p class="error">That username has been taken</p>'; }
  20. I tried this - and I got the same message: file_get_contents('$data, ../users/, users.txt'); //Reads the file contents if ($_POST['username'] == $_POST['$data']) { $problem = TRUE; print '<p class="error">That username has been taken</p>'; }
  21. Okay - I ran the file - no errors. I am looking into what you are saying and when I ran my script, I made sure my text file was empty and entered my name and my made up password and it told me that "that username has already been taken" .. So yes, I see that it is not pulling from the text file. But to be honest.... I have no idea how to get those contents into a variable. I thought they were in one! The $data variable. See how lost I am?
  22. So sorry - my error was this: Parse error: syntax error, unexpected T_IF in C:\xampp\htdocs\register1.php on line 45 and I did change the code a little now too: file_get_contents($file) //Reads the file contents if ($_POST['username'] == $_POST['username']) { $problem = TRUE; print '<p class="error">That username has been taken</p>'; }
  23. Okay - Great! that's just what I was looking for! I didn't know what function to use to call the script. Here's what I've got - only it returned an error. I am thinking it's because of this line here...if $_POST['username'] = $file. You stated I should be searching for the string of the username... I expect file should be replaced with something else.... But what? file_get_contents($file) if $_POST['username'] = $file { $problem = TRUE; print '<p class="error">That username has been taken</p>'; }
×
×
  • Create New...