KevinM1
Moderators-
Posts
5,222 -
Joined
-
Last visited
-
Days Won
26
Everything posted by KevinM1
-
And the error is...?
-
textarea issue \\\\\\\\r\\\\\\\\n\\\\\\\\r\\\\\\\\n\\\\\\\\r\\\\\\\
KevinM1 replied to $php_mysql$'s topic in PHP Coding Help
Why are you using htmlspecialchars only when magic quotes are turned on? And why are you using '@' to squelch errors on trim, of all things? -
Achievements should be part of each main user account. The sub sites should update that info when a user earns an achievement. A table with columns for userID, game/sub siteID, and achievementID would probably suffice.
-
What's everyone been up to in the world of Programming?
KevinM1 replied to phpSensei's topic in Miscellaneous
Finishing a video game review site, finishing the planning of a movie and television review site, and starting some work on a local sports site. -
PHP Class - What is it for and when to use it
KevinM1 replied to paddy100's topic in PHP Coding Help
Classes have to do with Object Oriented Programming. You should learn the basics of PHP (and scripting in general) before trying your hand at OOP. -
Maybe you should give us a clear idea as to what you're trying to do. All I can gather is that you want $q to come in from the address bar, and you want to use it as a switch to do something. The rest has been a series of "That's not what I'm trying to do."
-
Okay, time for a crash course in functions: The first thing you need to know is that functions have their own scope. This means that whatever is going on outside of the function will NOT be present inside the function. At least, not unless you explicitly pass those exterior values into the function. How are values passed into a function? The correct way to do it is to use the function's argument list. What is the argument list? Functions have a signature. The signature contains the function name and argument list. You may have looked at the PHP manual and seen something like: function name($arg1, $arg2) The part within parentheses is the argument list. So, if you need to use $q, you need to pass it into your function: function arr($q, $word) // <-- function definition - blueprint for the function, NOT code that executes immediately { /* do stuff with $q and $word */ } $q = $_GET['q']; arr($q, $word); // <-- function invocation, where arr finally runs, using the values you passed in
-
Gah! You're right. Man, I need to get to bed....
-
if ($pos_x < 30 || $pos_X > 240) { echo "You hit a wall"; } if ($pos_y < 30 || $pos_y > 240) { echo "You hit a wall"; }
-
Did you actually try turning them back on, like Adam suggested? The add-on/status bar for Firefox 4+ and Thunderbird 5 defaults to off.
-
how to hide Table 'table_name' doesn't exist message?
KevinM1 replied to $php_mysql$'s topic in PHP Coding Help
Did you read the part where it talks about using set_error_handler? Without setting a custom error handler, trigger_error will use the default handler, and simply spit out whatever you write in the parentheses to the screen. -
Dependency Injection, trying to understand it...
KevinM1 replied to MasterACE14's topic in PHP Coding Help
Yes. With the way it's used, that method really should be private. That would probably make it more clear as to its intent. Generally speaking, most likely. A DI/Ioc container has two jobs: 1. To wire up the dependency for an object with that object 2. To return that wired up object Now, you may not have to do something as robust as what that example showed. For example, if you had an object which needed a database: class DBContainer { private $db; public function __construct($db) { $this->db = $db; } public function getObjectThatNeedsDB() { $obj = new ObjectThatNeedsDB($this->db); } } Obviously, a canned example. Really, though, the example given by Symfony misses one key component - DI works best when dealing with interfaces (the actual language construct). That allows one to keep the DI definition the same while being able to change the underlying functionality of one, or both, of the components. An example would be a MVC controller which needed to access a repository: class BlogController extends Controller { private $repo; public __construct(IRepository $repo) { $this->repo = $repo; } // ... } class Container { public function getController() { return new Controller($concreteRepo); // <-- all controllers are derived from an abstract base class - assumes only one repository is needed } } If you needed to do some unit testing, or something else along those lines, you could then substitute $concreteRepo for, say, $testRepo without having to take a hatchet to your code. Hope this helps. -
This is exactly why I'm focusing on ASP.NET MVC. It's essentially Microsoft's version of RoR. A lot of the way it's structured is lifted wholesale from RoR, including the way packages are handled (NuGet = Gems). The only draw back is having to tie yourself to Microsoft's ecosystem, which, as we all know, can be expensive. The Website Spark and Bizspark programs help mitigate those costs, but they're still present. The point is, there's a small, but thriving, community of MVC devs. There are new packages added to NuGet all the time, everything from Facebook integration to IoC containers. The big names associated with MVC (Hanselman, Guthrie) write blog posts all the time, and are more than willing to help out on Twitter. PHP feels splintered. You have Joomla over here, Drupal over there, a cluster of frameworks (Zend, CakePHP, Code Igniter, Kohana, Symfony) in the third corner... There isn't any kind of unified front to rally behind. Maybe that speaks to PHP's flexibility, I dunno.
-
Program with what you want. Language evangelism is useless. FWIW, describing a language in terms of 'power' is nonsense. How do you measure a language's power? What's the metric? Unit of measurement? Either you enjoy a language or don't. Don't try to couch your reasoning in BS terms like 'power'.
-
Aside from a couple of typos (an extraneous semicolon at the end of convertTemp's signature, and forgetting to put $this->convertToFahrenheit in the same method), it works fine for me. EDIT: My code with the kelvin conversion removed - class Temperature { private $temperature; public function __construct($value, $units = "c") { $units = strtolower($units); if ($units !== "c") { $val = $this->convertTemp($val, $units); } $this->temperature = $val; } public function getTemp($units = "c") { $units = strtolower($units); if ($units === "c") { return $this->temperature; } else { return $this->convertTemp($this->temperature, $units); } } public function setTemp($val, $units = "c") { $units = strtolower($units); if ($units === "c") { $this->temperature = $val; } else { $this->temperature = $this->convertTemp($val, $units); } } private function convertTemp($val, $units = "c") { $units = strtolower($units); if ($units === "c") { return $val; } else if ($units === "f") { return $this->convertToFahrenheit($val); } } private function convertToFahrenheit($val) { return ($val / 5) * 9 + 32; } }
-
Also, a user should never see a PHP/database error. You should have a generalized error screen/helpful 404 screen, which would also do whatever logging you need to do behind the scenes.
-
It looks like it to me. Have you tried using it?
-
Uh...both of your code snippets should be within the same class code, for starters (they may actually be, on your end, but the way you're writing your code is odd in this instance). Second, like requinix said, there's no need to store different values for C, F, and k. The temperature is the same, just represented differently. Have the class do the heavy lifting. class Temperature { private $temperature; public function __construct($value, $units = "c") { $units = strtolower($units); if ($units !== "c") { $val = $this->convertTemp($val, $units); } $this->temperature = $val; } public function getTemp($units = "c") { $units = strtolower($units); if ($units === "c") { return $this->temperature; } else { return $this->convertTemp($this->temperature, $units); } } public function setTemp($val, $units = "c") { $units = strtolower($units); if ($units === "c") { $this->temperature = $val; } else { $this->temperature = $this->convertTemp($val, $units); } } private function convertTemp($val, $units = "c"); { $units = strtolower($units); if ($units === "c") { return $val; } else if ($units === "f") { return convertToFahrenheit($val); } else { return convertToKelvin($val); } } private function convertToFahrenheit($val) { // code to convert a temperature represented in Celsius to Fahrenheit } private function convertToKelvin($val) { // code to convert a temperature represented in Celsius to Kelvin } } This class stores its internal temperature as a measurement in Celsius, and does conversions to/from Fahrenheit and Kelvin respectively, when needed. It's as simple to use as: $temp = new Temperature(100); // boiling point of water in Celsius echo "In Fahrenheit: " . $temp->getTemp("F"); It's certainly not a complete class (no error/exception handling), but it should give you some insight into how to approach the problem.
-
What are the best security functions for registering?
KevinM1 replied to iStriide's topic in PHP Coding Help
First, you should address form validation. You likely don't want to even accept special characters, and what if someone tries sending the wrong kind of data (say, string data for a field you're anticipating numerical data for)? Stop the barbarians at the gate, and validate all incoming input. The most robust/customizable way to do this is to use regular expressions. Some links: preg_match http://www.regular-expressions.info/ There will be times when you'll want to allow others to supply input with HTML tags (like, say, a forum like this where people post code). To do that, run htmlspecialchars or htmlentities on the data before you output it to the screen (and not when you store it in your db). This will help combat XSS attacks. For SQL injection protection, keep using mysql_real_escape_string on string data. A better, if more complex alternative, is to use either mysqli or pdo for your database needs. They have prepared statements, which automatically escape all data being injected into those queries. -
There's a difference between hashing and encrypting. Hashing is designed to be one-way. Encryption is designed with the assumption that the thing being encrypted will eventually be decrypted. MD5, SHA, etc. are hash algorithms.
-
There's definitely an art to becoming helpfully unhelpful. You give too much, and people take advantage and neglect to even attempt to learn anything. Give too little, and you're a jerk who only makes the other person more frustrated. I like answering the questions which can be solved in a few posts, as anything that takes a page or more to solve generally degrades into "I really have no clue/am just lazy, and need the entire thing to be rewritten by someone else," which is definitely not my purpose here. The bite-sized, fundamental problems are right in my particular wheelhouse.
-
How to POST values to the custom fields in php file.
KevinM1 replied to t8mas062184's topic in PHP Coding Help
I'm still not 100% sure of what you're trying to do. That said, remember that $_POST is an array. You can obtain the key-value pairs in a variety of ways, even if they're dynamically generated (foreach, in_array, [m]array_key_exists[m], to name a few examples). This will allow you to check the kinds of values coming into the system, either in if/else statements, or a switch. -
How to POST values to the custom fields in php file.
KevinM1 replied to t8mas062184's topic in PHP Coding Help
Show us what you have so far, as your question is a bit vague. -
Wow, really good. A couple of things: The "What's The Hot" button at the top should simply be "What's Hot". Similarly, the grammar under the "Notify Me" area is awkward, as well as "Chick to last or next" (should be "Click to last or next"), etc. It's pretty obvious that English isn't your native language, but since this is a site written for an English-speaking audience, you should probably hire a native speaker to proofread what you have. I'm not sure if I like the "Notify Me" area being centered. You should play with it, and see if it looks better left justified, or perhaps in a different spot on the page altogether. All that said, very nice job! A few tweaks here and there (primarily language), and you'll be good to go.
-
Colors are better (not great, but better), but, again, not a fan: Why do the buttons have rounded rectangles - which alter the size of the menus - for a hover state? Why is there simply a list of photos on the main page, one of which (the second one) breaks the layout? Why are you using HTML to shrink images in the store - which causes noticeable image loading - rather than real thumbnails? Why do you have centered text? Why is your "Jump to Article" drop down not centered? --- I get that you're an amateur, but there's a lot of work that needs to be done if you're going to market yourself as a designer. Step one to advancing is doing homework. Are there sites in the same domain (business) as your client's? What do the good e-commerce sites do that is similar to one another? What are some cool sites you can use for inspiration (hint: http://www.smashingmagazine.com/2011/01/25/showcase-of-beautiful-and-fresh-ecommerce-websites/ )? No one is going to expect you to make a site that looks like it belongs to a Fortune 500 company (at least, not initially). That said, there's certainly a lot you can do to improve. Look at what the pros do, find the commonalities between them, and try to emulate it. You'll develop your own aesthetic over time, but you'll at least have the structural components down.