Jump to content
Larry Ullman's Book Forums

Jonathon

Members
  • Posts

    1064
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by Jonathon

  1. What I put above will work. You don't need to change the file_get_contents
  2. Close, $data = file_get_contents($file); This way you assign the returned value of the contents of the file, which you stored the location at $file. Now you have the contents of that file in the variable $data. So now you need to somehow check the form input against the contents in $data.
  3. Not exactly. $file = $mydata means all you're doing is assigning $mydata (that doesn't exist) to $file And secondly, if you could get all the data from the text file, if($_POST['username'] == $mydata) would only work if there was only 1 record in the file, because file_get_contents() returns a string. So entry 1 was say 'myusername' then another person registers and their username is 'jonathon', so then file_get_contents() would return 'myusername jonathon' as 1 string, so every other time the check was done it would likely fail.
  4. Look at my last post and lets start there. But think about the if statement here. your asking php if the submitted username from the form is equal to the submitted file location. You are only submitting the username to be the checked. That's all, the file is not posted to the server it is already on the server. And even if you were able to do this, you're not actually using the data from the text file as that is all still in the file_get_contents()
  5. Lets concentrate on just accessing the file first and getting information from it. I suggest you just put a username in it just so you can check that its pulling data from the file. $dir = '../users/'; $file = $dir . 'users.txt'; So $file holds the reference to where the text file is. so file_get_contents($file); Gets all the data. So how would you think that you could get and use the data from the line above?
  6. the semi colon is missing from the first line. What text editor are you using? secondly file_get_contents($file); doesn't do much because you need to assign it to a variable. Then query the variable, which is to say that this line if ($_POST['username'] == $_POST['username']) { is wrong. Look at what you're checking here, basically its saying is the input i put into the form the same as what i put into the form. Which is always true, a bit like is 1 = 1. So work to get the contents of your file into a variable, then we need to check the input against what's in the txt file.
  7. If possible remember to tell people what the error is. Secondly, remember that '=' is an assignment operator not a equality '==' / '===' operator. Also get used to using the php manual its very useful, it shows you what arguments it takes, if there are any optional arguments, what it returns and usually examples of how to use it. http://php.net/manua...et-contents.php Notice that it says here that "except that file_get_contents() returns the file in a string" Essentially your code above is logically and syntactically invalid. You need to use the $_POST['username'] value to see if it exists within the value that is returned from the file_get_contents()
  8. At this stage in your reading this is of absolutely no use to you (sadly). You will meet magic_quotes i'm sure. But ignore them for the moment. This style of PHP is also Object Orientated (OOP), which you won't be able to follow just yet either. so if you see anything like $obj->query or anything like -> you're dealing with OOP so you can ignore it. As for your problem I suggest an approach to this, though there is always alternative ways to program. Well after this line if (!$problem) { // If there weren't any problems... if (is_writable($file)) { // Open the file. You could use this function to get the contents of the txt file. file_get_contents() Look at this function on the PHP.net to see what it takes as arguments and what it returns. Then from there its a case of searching the string for the username.
  9. remove this echo '<div class="title"> <h4>Manage Your Account</h4> </div> <ul> <li><a href="renew.php" title="Renew Your Account">Renew Account</a></li> <li><a href="change_password.php" title="Change Your Password">Change Password</a></li> <li><a href="favorites.php" title="View Your Favorite Pages">Favorites</a></li> <li><a href="history.php" title="View Your History">History</a></li> <li><a href="recommendations.php" title="View Your Recommendations">Recommendations</a></li> <li><a href="logout.php" title="Logout">Logout</a></li> </ul> '; and replace it with what you want?
  10. Well you can validate the form inputs. Then when you came to writing the data, you'd need to know prior to that process whether the username existed, so you'd need to get the contents of the file and parse it to check. Then depending on the outcome write the data or produce an error as the username already exists.
  11. You need to take the validated username and check it against the usernames listed in the text file. What does the txt file contain, just usernames?
  12. I'm sure the path of the file is returned in the error message, so maybe use a regex or substring inside an if to tell if the file came from that sub directory and if it did, don't invoke it?
  13. I think (although I don't have the book, I'm on my phone and its very late ha) that the idea seems to be that you take the forms input and validate that it isn't empty and that the username isn't in use before you try to make them a directory.I don't think you currently do this.
  14. I'm not really sure on the ins and outs of it. I think I had to use it on an I'd field which was an INT so I found that strange as its just a number. Sorry I can't be more help, but at least it works.
  15. Yes Andrew I think had the solution for this. Search for illegal in the forum and you'll see the fix. I'd send you the link but I'm on my phone.
  16. Well if yours is similar to mine function my_error_handler ($e_number, $e_message, $e_file, $e_line, $e_vars) { Can't you run a check to see the file that it came from? Wouldn't all the errors be from the same file? i.e calander.php (or whatever it is) regardless of the page?
  17. If the calendar script is only used in one page or a few, reference the URLs of those pages in an array and check inside the config file whether you are on that page then if you are on a calendar script page then don't invoke the custom error handler. Not ideal but would at least stop the dreaded emails, I hate it when i get 5 or 6 saying you messed up. Let alone 133
  18. I have a feeling that the mysql_query() Only needs to takes 1 parameter, it can take a resource secondly as an optional argument, so try just mysql_query($q); But also write mysql_error() into your code to pull up why it fails still.
  19. Implement debugging into the script to see why the script fails. mysql_error(). Then it should tell you why it's failing exactly
  20. So the query is failing. Do you have access to the mysql client or phpmyadmin? Try the queries in there. See what error is returned or the script itself.
  21. It's just Index, if you are new to MySQL or PHP this probably isn't the book for you as it does require comfort with both technologies though.
  22. In a word no, the operators are exact, so you need to use them as specified. (++)
×
×
  • Create New...