Jump to content

Alex

Staff Alumni
  • Posts

    2,467
  • Joined

  • Last visited

Everything posted by Alex

  1. I didn't realize that you were already checking to see if the variable was set, so kenrbnsn's solution is more fitting. The code you're asking about is the ternary operator.
  2. The way you have it $searchTerm will either be true or false, whatever isset returns. I think you want something like this: $searchTerm = isset($_GET['search']) ? $_GET['search'] : '';
  3. In that context $a has no value. So you're trying to access a property with a null name, which obviously doesn't exist. You could however do this: $a = 'a'; $ob->$a; When calling the property of a class you just don't use the dollar sign in front of the variable name, that's just how it is.
  4. That code isn't supposed to change any value. It will insert a new row..
  5. You should be using for not foreach: for ($types = 0; $types < 4; $types++) {
  6. In most cases it's more of a precaution. It just ensures that you don't accidentally include it more than once when you know it only needs to be included once. It's always a better idea to add the safety than to say "I'll be careful". Something else to worry about is if you plan on distributing the code you want to make sure that others using your code don't make a mistake. In situation like these using require_once vs require can be helpful.
  7. if(!preg_match('~^[^$%@!]+$~', $str)) { // contains invalid characters }
  8. $enddate = date('Y-m-d', strtotime("now")); Would be the same as.. $enddate = date('Y-m-d');
  9. I'm trying to increase a partition's volume using the partition manager that comes with windows 7 and I'm running into a problem. Last time I was attempting to this I looked up my problem and eventually found out that it was because of the unallocated space that I have on my hard drive is located to the left of the partition I'm attempting to increase. I've heard that there might be some partitioning software that will allow me to extend partitions from unallocated space located to the left of the partition, but I'm not sure if that's true or not. Anyone know any partitioning software or other method that I can use to get this to work?
  10. You need to convert literal line breaks, \n, into HTML line breaks, <br />. You can use the replace() method to do this. document.something.innerHTML = document.yourtextarea.value.replace("\n", "<br />");
  11. Just add a comma to the class: /^[a-zA-Z\.\-\'\s,]*$/
  12. echo parse_url('http://www.remotesite.com/images/folder/image.jpg', PHP_URL_PATH); parse_url
  13. You need to post relevant code. Normally you'd do something like this: $sql = "..."; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); echo $row[$name];
  14. You can debug_backtrace to tell what line in what file the current function being executed was called from.
  15. You shouldn't use it on input variables because then anyone can inject unwanted variables into your script. Say you used it on the $_GET array. Someone accessed your website like file.php?auth=1, and in your code you happen to have a security check to see if($auth){ ... }. This is what register_globals (http://us3.php.net/manual/en/ini.core.php#ini.register-globals) does. extract does have its uses sometimes, but in this case it's not something that you should use. Here's an article that explains the problems that register_globals creates, http://us3.php.net/manual/en/security.globals.php
  16. You can prevent duplicate rows by using a DISTINCT clause in your SQL query. That's more of a MySQL question though, so if you want help with that head over the MySQL help forum.
  17. You don't need a class for this, although you could very well make one yourself. There are simple formulas. Example: 1 meter is ~3.280839895 feet, so: function metersToFeet($meters) { return $meters * 3.280839895; }
  18. It doesn't pull it from a database. It calculates it based on the unix timestamp of the computer that PHP is executing on.
  19. Or you could use extract to get the same effect. If you're using this on the $_POST array, or any other input array for that matter, it's essentially recreating register_globals, which is a huge security risk.
  20. Why would you have that year updated? The year when displayed along side the copyright notice is simply the year when it was registered or claimed. Oh, and to answer your question, there's no need to use a database for something like this.
  21. You have two links there, the other one seems to have the same problem. print("<tr><td class=\"lista\"><b><a title=\"".$language["FIRST_UNREAD"].": ".preg_replace("/Re:/", "", $trow["title"])."\" href=\"smf/index.php/topic," . $trow['tid'] . ".msg" . $trow['goto_last_post'] . ".html#new\" target=\"_blank\">" . substr($title,0,30) . "...</a></b><br />".$language["LAST_POST_BY"]." <a href='smf/index.php?action=profile;u=" . $trow['last_poster_id'] . "' target=\"_blank\">" .$trow['last_poster_name'] ."</a><br />On " . date('d/m/Y H:i:s',$trow["last_post"]). "</td></tr>\n");
  22. You should look at the HTML output and see what's wrong. It looks like you have an extra \", try this: print("<tr><td class=\"lista\"><b><a title=\"".$language["FIRST_UNREAD"].": ".preg_replace("/Re:/", "", $trow["title"])."\" href=\"smf/index.php/topic," . $trow['tid'] . ".msg" . $trow['goto_last_post'] . ".html#new\" target=\"_blank\">" . substr($title,0,30) . "...</a></b><br />".$language["LAST_POST_BY"]." <a href='smf/index.php?action=profile;u=" . $trow['last_poster_id'] . "'\"target=\"_blank\">" .$trow['last_poster_name'] ."</a><br />On " . date('d/m/Y H:i:s',$trow["last_post"]). "</td></tr>\n");
  23. You could create third table to link the posts and media tables multiple times. Such a table could contain id, post_id, and media_id. That way you could link media to multiple posts.
  24. And that won't exactly work all the time. Say someone has a Username like David99, that query would also pick up vid99, avid9, etc..
×
×
  • 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.