Jump to content

Alex

Staff Alumni
  • Posts

    2,467
  • Joined

  • Last visited

Everything posted by Alex

  1. It's a result of mysql_query return boolean false. To see the error replace: $result = mysql_query($sql); with: $result = mysql_query($sql) or trigger_error(mysql_error());
  2. You're closing the PHP tag before defining the function. ?> # Function for mailing the Username for a given email address function mail_username() {
  3. $sql = 'SELECT `login` FROM `users`;'; $run = mysql_query($sql, $link); $users = array(); while($row = mysql_fetch_assoc($run)) { $users[] = $row['username']; } echo "'" . implode("', '", $users) . "'";
  4. Sure it does, try this code: if("test%".match('^[a-zA-Z0-9]+$')) { alert('matched'); } else { alert('did not match'); }
  5. Of course. Use imagerectangle instead of imagefilledrectangle.
  6. There's no need to load the memory expensive regular expression engine for something like this. if(strpos($string, 'Peanut Butter') !== false) { // contains Peanut Butter } else { // doesn't contain Peanut Butter }
  7. If you want to access the file through a PHP script but don't want it to be directly accessible then just put it outside your document root.
  8. You mean take out everything out of a string that is not "Peanut Butter" or match a string if it does not contain "Peanut Butter"? Either way you don't need regex for this. If the former just to str_replace to remove "Peanut Butter" from the string and you have everything that's left. If the latter and you just want to see if a string does or does not contain "Peanut Butter" use strpos.
  9. ~^[a-z0-9]+$~i Would work. But you don't need regex for this. Just use ctype_alnum.
  10. It is a PHP question because it deals with the PHP syntax of constructing the MySQL query and not about the syntax of the query itself. Did you try my solution?
  11. This is more of a PHP syntax question, so I'm moving it to PHP coding. To answer your question: $sql = "SELECT * from $tablename"; You should really be validating that value though.
  12. Are you sure? It works for me: $text =<<<TEXT <a href="forum.php?f=108">Other Games</a> TEXT; preg_match_all('/<a href="forum\.php\?f=(.*?)"[^>]*>(.*?)<\/a>/is', $text, $matches); print_r($matches); Output: Array ( [0] => Array ( [0] => <a href="forum.php?f=108">Other Games</a> ) [1] => Array ( [0] => 108 ) [2] => Array ( [0] => Other Games ) )
  13. Try this: /<a href="forum\.php\?f=(.*?)"[^>]*>(.*?)<\/a>/is
  14. Your outputting all this html before calling header: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>MyTest</title> <body>
  15. Yeah, that's the correct book. Not exactly. It should be as simple as possible. Say you write an image manipulation class. After you're done to be able to utilize all the functionality you shouldn't have to mess with internal variables, etc. There should be a straightforward API that allows you to do what you need without knowing what's going on inside. All of the logic should be self-contained in the object so you don't have to worry about it when using the object. I mean like this: class Utility { static public function FileSize(...) { // ... } static public function TimeSince(...) { // ... } } Where maybe FileSize will take an integer and convert it to a nice format like KB/MB/GB, etc.. And TimeSince may take a timestamp and tell you in a nice fashion how long ago that was (eg. '54 minutes ago'). By declaring them static you can access them like this: Utility::FileSize(...); Utility::TimeSince(...); Without going too much into detail (you can look this up on your own) static methods and properties of a class don't require you to have an instance of the class to use them. You can read more about the static keyword here. Again, I'm not saying that this is particularly useful and offers any real advantage because grouping functions like this is not necessarily better than grouping them by the file in which they are stored. Just saying that you may see this sometimes.
  16. Well isn't that what you want to do? If so then yes you should learn how to do it.
  17. JQuery and AJAX are completely different things. JQuery is a popular JavaScript library that implements easy ways to utilize AJAX technology. The load method used in theverychap's post above is an example of one of these easy methods.
  18. What exactly would the purpose of that be? Calling call_beach() would be exactly the same thing as calling beach(). If you need to call the function from inside the function go ahead, what's stopping you? Just make sure you don't create an infinite loop.
  19. If you're not inserting it into the database, and just previewing it you don't need to escape the data for MySQL yet. That's what's causing your problem.
  20. You can't rely on the contents of $_POST in that you can't expect it to contain all of the fields from the form. It's possible someone sent information to the page without those fields. In other words, it would be possible for a required field not to be in the $_POST array, but because you're only looping through it to check if fields are empty the error wouldn't be caught. Instead you should check to see if each field is set and meets requirements explicitly. if(isset($_POST['username'], $_POST['other_field']/*, ...*/)) { // Check to see if all fields are set if(!empty($_POST['username']) /* Other validation required here */) { } // ... }
  21. I can't think of any particular online OOP tutorials offhand that were specifically useful. One book that I have, and would highly recommend, is PHP Objects, Patterns and Practice. Using OOP techniques you should be making your life easier, not harder, so if you find that using OOP is making things harder on you then you're not using it correctly. Different accessibility keywords allow you to maintain encapsulation. Briefly this means that you should not have to know how an object operates internally to be able to take advantage of its functions. You might compare this to a car; you know that if you perform a certain operation, like changing gears, the gear is changed. You don't have to know exactly how that works internally, and you shouldn't have to. Similarly if you have an object to perform a certain task you shouldn't have to know exactly how it operates on the inside, all you need to know is that if you call some method X you will get an expected and predicable result. These accessibility keywords allow you to ensure that properties and methods that shouldn't be touched from the outside aren't. If you're just storing a bunch of arbitrary static functions in a class usually there isn't much of a benefit. You might see this done sometimes in like a Utility class or something similar where the only benefit is, as you mentioned, to group similar functions together.
  22. What does SQLskip() do?
  23. You said the solution, so what's the problem? echo str_replace('<br />', '', $page[$rand_value[0]]) . "\n";
  24. You should use preg_split to split a string by a regular expression. But in that case I don't see why you can't use explode, you're not even using a regular expression.
  25. I'm guessing you have some kind of verification code on listtest5.php that checks if a certain cookie is set and your problem is that you're setting the cookie after you call exit(); so that bit of code will never execute. //set authorization cookie setcookie("auth", "1", 0, "/", "whereever.com", 0); header("location:listtest5.php"); exit();
×
×
  • 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.