Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by KevinM1

  1. Changed my name from: Nightslyr To: KevinM1. It was time.
  2. Or, you could use htmlentities to replace tags with their entity counterparts. The script text (i.e., <script>blahblahblah</script>) would appear on your screen as text, rather than execute.
  3. So, what are you asking for, specifically? We can't help unless we know: What you expect your code to do. What's actually happening (including errors, warnings, notices, and any unexpected output). What your current code is.
  4. It's returning 0 because you're not actually returning any value from your performCalculation function. Functions have their own, unique scope - what happens within them won't be 'seen' by the rest of the script unless you return a value from the function, and assign that return value to a variable in the parent scope, like so: function performCalculation() { // bunch of code return $total; } // main script $myTotal = performCalculation();
  5. file_exists takes a directory path, not a URL.
  6. Wow...that's going to take some time to get used to.
  7. Eh, I think it can remain here. crmamx is looking for overall site critique, which includes, but is not limited to, critique on his content. The CSS board is for specific CSS questions, which isn't what crmamx is asking/looking for.
  8. Is your safe() function in the same file or include-ed in the email code you're using? Your main script needs to be able to 'see' the function.
  9. You mean $row['rsTown']....
  10. Well, there's really no set answer to these kinds of questions because it depends on the context of your current situation. OOP is filled with "Don't do X, unless Y" kinds of situations. Accessors fall into that group. Not all objects need accessors. But some (data objects) rely on them to be useful. The key is to figure out who needs access to what in order to work. Here's another one for you: PHP lacks a struct-like data structure. In order to fudge it, a lot of developers create small, simple objects with public fields. Not a good habit to get into in a general sense, but not entirely horrible if you're only dealing with POD (plain old data). For example, Kohana's ORM does this because model objects are a 1-1 map of a db table row, so it streamlines assignment. The only meaningful activity connected to the object is saving its data back to the db. But, yeah, I hear you. It can be maddening in the beginning because a lot of it boils down to context or opinion.
  11. As you found out, that's exactly what I'm saying. Also, again, don't be paranoid about having things public. How else can objects talk to one another, let alone be instantiated? Of course fields should be either private or protected, but most of the methods you'll write will be public. A constructor is simply a method. And, yes, accessors do have their place as well. Hell, C#, a language that's much more object oriented than PHP, has a property mechanism just for that reason. A lot of objects need to know about other objects' current state in order to work. Look at just about any object that represents a database record. How are you going to get at its data without an accessor? You linked to an article about how accessors are bad, but did you ever bother to read the comments? They're pretty enlightening: http://www.javaworld.com/community/?q=node/1759#comment-32951 It's not scary. It's written very plainly. The biggest hurdle is that the examples are written in C++ and Smalltalk. Their syntax is similar enough to PHP's to make it a non-issue.
  12. You're not planning on making all your classes static or Singletons, are you? Nope. Not at all. But based on what you said, it sounds like I can make all constructors "private"... TomTees Not in the way you're thinking. You can't make them private and expect normal behavior, which is why I specifically mentioned Singletons and static classes. Singletons use a static method to return an instance of itself. There can only be one instance of a particular Singleton in existence EVER. Singletons are also global in nature because they use a static method for creation/assignment. Best to stay away from them. Generic static classes shouldn't be instantiated at all. Instead, data is passed into a static method and a result comes back, often an object. I'd say the vast majority of classes you'll write will have public constructors. That's okay. Encapsulation is good, but there still needs to be a way to turn on an object and initialize it somewhere in the system. You should do yourself a favor and buy the Gang of Four's book. It will address all these fundamental questions and provide relevant examples.
  13. You're not planning on making all your classes static or Singletons, are you?
  14. From what was described before, you could call the __Constructor repeatedly even if you hadn't instantiated yet. (Maybe I misunderstood?!) Yeah, I think you misunderstood. Calling the constructor IS instantiating an object. Whenever the word 'new' is written an object is being instantiated. Now, you don't need to DEFINE a constructor. If you don't define one, PHP will simply invoke the default constructor, which doesn't do anything but tell PHP "Hey, this is an object." You CAN make a constructor private. This is used when you want to deny public/multiple instantiation. It's a critical part of the Singleton pattern and other static classes (Factories).
  15. If it is left "Public", can anyone tamper with it? TomTees It can be executed (and will instantiate the object), and it can also be overridden. So you just have to live with it being "public" and hope your constructor doesn't get hacked, huh? :-\ TomTees How would it get hacked?
  16. Doesn't matter in either case. EDIT: In JavaScript, brace position does matter. It's always best to keep the opening brace of a function on the same line as its name and argument list in JavaScript.
  17. It's a style thing. A lot of coders prepend an underscore to private members to denote that they are private. It improves readability, but has no functional meaning. Yes.
  18. Thanks, That worked perfectly Now I'm trying to understand why. I thought an html tag would not work inside php code but obviously it can if its done right. This code builds the HTML of the form's dropdown options. This is a very common use of PHP. Remember how the general HTTP request cycle goes: Request to server -> server points request to proper PHP script based on the address -> script processes request, formulates results, and generates HTML, either by writing it dynamically or using templates -> results sent back to browser -> browser renders page and runs JavaScript (if any is there). PHP - or any server side scripting language, for that matter - would be pretty useless if it couldn't write HTML.
  19. This topic has been moved to Website Critique. http://www.phpfreaks.com/forums/index.php?topic=311075.0
  20. You assigned '' to $column, so when you use $row['$column'], you're actually attempting to access $row[''], which obviously doesn't exist. In order to access a table row column, you need to either know the column name, or use a foreach to cycle through them all. foreach ($row as $key => $value) { echo "Column name: $key -- Value: $value"; }
  21. Try: $sql = "UPDATE blog_dl SET title = '$title', body = '$post', poster = '$by' WHERE id = $id LIMIT 1;"
  22. I'm not sure how many times I need to say it, you need to SELECT a field. I'm not selecting a field, I'm just seeing if it exists. In order to see if a field exists, you need to select it. This is SQL 101.
  23. There's a boolean you can set in mysql_connect that will force it to create a new, parallel connection to a db: mysql_connect However, I think it only applies if you're trying to attempt multiple connections to the same db. If the db's are actually different, then the db handle you create during mysql_connect should be enough. Can you show more code in how you're creating and using these connections?
  24. You're kind of shooting yourself in the foot with the way you're trying to go about it. For one, your function has some issues (a counter defined within a function won't persist, add_input is not a variable, etc), and you're trying to do too much inside of it. Let's make it simple: <html> <head> <title>Adding a form input</title> </head> <body> <table id="add_episodes" class="editor" border="0" cellspacing="0" cellpadding="5"> <tr> <td><input size="3" type="text" name="number" /></td> <td><input type="text" name="title" /></td> <td><input type="button" value="Add another text input"></td> </tr> <tr> <td></td> <td></td> <td> <input name="entry_id" type="hidden" value="<?php echo $id; ?>"> <input class="input submit" type="submit" id="addInput" name="submit" value="Add <?php echo $type; ?>"> </td> </tr> </table> </body> <script type="text/javascript"> var addInput = document.getElementById('addInput'); var count = 1; var limit = 50; addInput.onclick = function(){ if (count == limit){ alert("You have reached the limit of " + limit + " inputs"); return false; } else{ addToForm('add_episodes', 'number'); addToForm('add_episodes', 'title'); ++count; return true; } } function addToForm(divName, type){ // function body goes here } </script> </html> I left the addToForm function body blank because you'll need to rework it a bit to get it to work (you need to figure out exactly what element to append to, as I can't see an add_input element anywhere). This should give you the basic idea, though. Notice that I've added an id of "addInput" to the submit button, and that there's no onclick call within the element itself. I prefer an unobtrusive style of coding, and I find it makes it easier to read and maintain code when it's written like this. YMMV.
  • 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.