Jump to content

Adam

Moderators
  • Posts

    5,717
  • Joined

  • Last visited

  • Days Won

    6

Everything posted by Adam

  1. By 'environment variable', do you mean putenv and getenv? I don't really see any benefit to this since they only exist for the life of the request.
  2. That's because the click event is only bound to the existing #next element. When you regenerate the HTML it's a brand new element, just with the same ID. Look into the live() method (or on() if you're using jQuery 1.7) that will bind the event to any current or future element(s) matching the selector.
  3. That's kind of the problem; you don't seem to listen to what people are saying and end up wasting their time. I appreciate regex can be quite cryptic at first, but having been told four or five times you need to include ^ and $, the latest code you posted still didn't contain both of them. Read what people have put until it properly sinks in, then check the code you're working on to see if it reflects what you've been told.
  4. Possibly? Can they have more than one image? This is your site.
  5. Are you trying to increment a number on the end of the file if there's a matching name? So original is "foo.jpg", next uploaded with the same name would be "foocopy1.jpg", next "foocopy2.jpg", etc. If so your code is all over the place, and you're inserting the file name into the database before actually knowing what it will be called. Personally I would just append a timestamp and pass the filename through md5(), as opposed to keep incrementing a number on the end. If you would rather do it this way though, I've quickly thrown together this function which should do the trick. Please read the comments and analyse the code (researching online if needed) before asking questions on something. function getNthFilename($filename, $target_dir) { // Make sure the filename actually does already exists if (!file_exists($target_dir . $filename)) { return $filename; } // Define the copy filename text $copy_text = $filename . 'copy%d'; // Define the number to increment $copy_num = 1; // Define the first copied version of the filename to test $copied_filename = sprintf($copy_text, $copy_num); // Loop through until we find an available name while (file_exists($target_dir . $copy_file)) { $copied_filename = sprintf($copy_text, ++$copy_num); } // At this point we should have a valid name return $copied_filename; } You can use it like: // Get the filename $filename = $_FILES['foto']['name']; // Get an absolute path for the target directory $target = realpath('../images') . '/'; // Get the valid name for the file $valid_filename = getNthFilename($filename, $target); After then successfully uploading the image, and only then, you want to insert the $valid_filename into the database. Edit I've corrected a quick typo. Might be more, I haven't tested this..
  6. I don't follow your post at all.. but if you've added [] to an input, you've turned the data into an array. To access this in the PHP, you just access it as you would before. Instead of getting a string back though, you get an array of strings. You'll need to read more about arrays in the manual if you don't understand.
  7. You should post any additional information in this thread rather than a PM, if you want more assistance.
  8. As I said you need to add in ^ at the start of your pattern, which will match from the very start of the string, and $ at the end which will match to the end of the string. Currently your pattern makes a match but it doesn't matter where it is, so you can still have invalid characters on the outside of the match: this may or may not be valid 1 Green and blue show the matches your pattern will make. As you don't have the start/end string boundaries, then 1 is just simply not matched but the string is classed as valid. As dharmeshpat also pointed out, in order to match your string you will need to allow spaces, which you can do either with \s, which means any type of white-space (spaces, line breaks, etc), or with a single space in the character class: /^[a-z ]+$/
  9. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=351154.0
  10. All that regular expression is doing is looking for a single a-z character within a string. To ensure it can only contain that, you need to add ^ and $ to the start and end of your regular expression respectively. These special characters mean the start and end of the string, otherwise you'll just be searching for a pattern somewhere in the middle of the string. Also as I said your pattern is also only looking for a single character. You need to add +, as we spoke about yesterday, after the character class: /^[a-z]+$/
  11. Do you know how to do one query?
  12. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=351100.0
  13. Sounds as though you're going down a bad route here. It doesn't look like on the site that Lightbox2 supports any other content than images. I would just go with a different package that does; Fancybox, Facebox, etc.
  14. Are you meaning to query 3 separate tables over 3 separate queries, or query 3 relational tables in 1 query?
  15. + and {1,} mean exactly the same thing. * is also an alias of {0,} which means zero or more times. Your regular expression (no offence) is very simple, but when you move onto longer and more complex patterns they are a subtly large benefit. There's no need to use curly brackets unless you need to specify two or more times, three or more times, etc.
  16. Ah.. You're missing a plus after \d, to mean 'match once or more'. That will effectively then match anything up to the next character which isn't a number.
  17. If you have two digits directly next to each other, you just need to use one \d because it will match both at once.
  18. Yes
  19. The code should, and does, work as expected. It must be something your end that's causing the 28 to disappear..
  20. Why do you manually create an object instead of using this, then only pass in the selectedIndex so that you have to recreate the same object within the function, when you could have just passed it in? whichPet(this); function whichPet(select) { alert("You selected " + select.options[select.selectedIndex].value); }
  21. Use trim to remove any white space in $line.
  22. Adam

    php

    Just because AJAX is used doesn't mean it depends on Javascript being turned on. Um, indeed it does. You cannot create Ajax without JavaScript. I think scootstah was just trying to say that in order to use AJAX, you don't need to leave non-JS users in the lurch. If you're using a shared host it's possible that they have purposefully prevented you from showing the errors. Is there an error log somewhere in the directories you have access to? It will probably be called "error_log", or postfixed with that.
  23. Check my latest reply.. Didn't notice your edit when I posted my first.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.