As a general rule, I let PHP do complex math, but let MySQL do anything up to that. MySQL can do a lot of things PHP can, but PHP can be much more efficient for the more complicated stuff.
Agreed. But it would only be at that point where I would even consider trying to use multiple databases. But if you're handling that much data, I'd assume there would be someone around you that would step in and say "Hey, that's not a good idea."
MySQL should be able to handle 'millions' of rows without much of a problem. It's when you get into the hundreds of millions or even billions of rows that you should start considering migration to multiple databases, or even a new database system.
What probably happened was you edited some code which then failed to run (due to syntax errors, more than likely). I get 500 errors a lot when I'm messing with hooks and screw something up.
There's no real reason to not use a framework. It will do most of the hard stuff for you (database abstraction, validation, session management, among many other things) that you would otherwise have to write in yourself dozens, if not hundreds, of times. Really, the only way a framework can hurt you is if you don't at least have an idea of how it's doing what it's doing. For example, if you're doing a $this->data->save($this->request->data) within a framework, you should know that what this is actually doing is taking the POST data and updating a row in the database.
Frameworks also get you in the OOP mindset with PHP, which is hard for some people to do. But, once you've figured it out, it will be like second nature and it will also make the jump to RoR or Django a little easier.
PHP is a good language. It's not the best, for sure, but there are countless well-known sites out there that are based on it. Your gripe with it may be because you've been doing it the hard way (that is, without a framework). Try picking up a framework (they all have their ups and downs, and everyone has their opinion on the 'best' one, so just do some research to find one that sounds good to you) and see how you like it. If you're still not feeling it, try out RoR or python/django. Then if you're really desperate you can try out .net.
Do know that there are a plethora of PHP jobs out there right now, though, so it's a great thing to have in your toolbox. It may be an entirely different story in a few years however.
This is really the simplest solution for both you and the end-user. You don't have to write an "install script" and they only have to change one value.
You can set the time() function to a variable, then return it. Or you can return an entire div with all the information you want in it, then change the .append(comment) to .append(data).
So something like this in add_comment.php: echo true; becomes echo "<div class='each_comment'><small><em>$time_variable</em> </small><br />$comment</div>";
Then in index.php change .append(comment) to .append(data).
I worked off of your code as much as possible, while also cleaning it up a bit. I was attempting to get you as close as possible to a working version of what you have now while not just spoon feeding you everything. There are still some major "errors" with this code, but this should give you a nice starting point. Good luck!
It's not calling the function because it's not 'actually' there. Include the users file (or whatever you've called it) in the comments file and change get_comments back to post_comment and you should be good to go.
Change post_comments($_POST['comment']); to get_comments() and see if you still get an error. It won't really do anything, but you'll know if it's still calling a function like it should be.
In that case, can you post what's in comments.php? The error seems to be coming from the call on line 7 of that file and line 7 of the code in the original post doesn't have a call to post_comments().
Can you post the relevant code from index.php? I'm not sure why it would have no problem echoing get_comments() but return an error with post_comments().
Also, change post_comments($_POST['comment_text']); to post_comments($_POST['comment']); since your post variable is called "comment" not "comment_text".
Also, it seems you're sending GET and POST data in the same request... why?
EDIT: Just looking at you code, I'd say $comment = sanitize(strip_tags($comment)); is your problem. PHP doesn't have a "sanitize" function. You probably want just $comment = strip_tags($comment);
If you do go the University route, don't just waste the spare time you'll have. Work on your own projects or start freelancing in your free time. Too many people think that their degree entitles them to a job, when really all it does is open a few more "prestigious" doors for you (that is, lets you confidently apply for jobs that 'require' a bachelors degree). Having a portfolio of works along with your degree is what really matters. It shows potential employees that you put in the time at University and got your degree, but you also went above and beyond your degree and learned/worked on some 'real' stuff.
As a general rule, I let PHP do complex math, but let MySQL do anything up to that. MySQL can do a lot of things PHP can, but PHP can be much more efficient for the more complicated stuff.
Agreed. But it would only be at that point where I would even consider trying to use multiple databases. But if you're handling that much data, I'd assume there would be someone around you that would step in and say "Hey, that's not a good idea."
MySQL should be able to handle 'millions' of rows without much of a problem. It's when you get into the hundreds of millions or even billions of rows that you should start considering migration to multiple databases, or even a new database system.
What probably happened was you edited some code which then failed to run (due to syntax errors, more than likely). I get 500 errors a lot when I'm messing with hooks and screw something up.
got interested after reading this. thank you. such a good post.
There's no real reason to not use a framework. It will do most of the hard stuff for you (database abstraction, validation, session management, among many other things) that you would otherwise have to write in yourself dozens, if not hundreds, of times. Really, the only way a framework can hurt you is if you don't at least have an idea of how it's doing what it's doing. For example, if you're doing a
$this->data->save($this->request->data)within a framework, you should know that what this is actually doing is taking the POST data and updating a row in the database.Frameworks also get you in the OOP mindset with PHP, which is hard for some people to do. But, once you've figured it out, it will be like second nature and it will also make the jump to RoR or Django a little easier.
PHP is a good language. It's not the best, for sure, but there are countless well-known sites out there that are based on it. Your gripe with it may be because you've been doing it the hard way (that is, without a framework). Try picking up a framework (they all have their ups and downs, and everyone has their opinion on the 'best' one, so just do some research to find one that sounds good to you) and see how you like it. If you're still not feeling it, try out RoR or python/django. Then if you're really desperate you can try out .net.
Do know that there are a plethora of PHP jobs out there right now, though, so it's a great thing to have in your toolbox. It may be an entirely different story in a few years however.
This is really the simplest solution for both you and the end-user. You don't have to write an "install script" and they only have to change one value.
What's funny is that it's not hard to go back and make it more secure, just no one ever bothers to.
It looks like you're well on your way. Keep it up.
If you get too stuck, feel free to send me a message or post a new thread. There's tons of people here willing to help you out.
You can set the
time()function to a variable, then return it. Or you can return an entire div with all the information you want in it, then change the.append(comment)to.append(data).So something like this in add_comment.php:
echo true;becomesecho "<div class='each_comment'><small><em>$time_variable</em> </small><br />$comment</div>";Then in index.php change
.append(comment)to.append(data).I worked off of your code as much as possible, while also cleaning it up a bit. I was attempting to get you as close as possible to a working version of what you have now while not just spoon feeding you everything. There are still some major "errors" with this code, but this should give you a nice starting point. Good luck!
index.php
DONTLOOKATME.php
add_comment.php
db.php
Alrighty. I think I'll take a crack at it anyway just because I've found myself with some free time. If you want the files let me know.
If you'd like, I can write up a quick little something to show you how I would approach this and you can work off it.
It's not calling the function because it's not 'actually' there. Include the users file (or whatever you've called it) in the comments file and change
get_commentsback topost_commentand you should be good to go.Change
post_comments($_POST['comment']);toget_comments()and see if you still get an error. It won't really do anything, but you'll know if it's still calling a function like it should be.Wait, so comments.php is just this code?
Where is the code you posted above this in the OP?
In that case, can you post what's in comments.php? The error seems to be coming from the call on line 7 of that file and line 7 of the code in the original post doesn't have a call to
post_comments().Can you post the relevant code from index.php? I'm not sure why it would have no problem echoing
get_comments()but return an error withpost_comments().Also, change
post_comments($_POST['comment_text']);topost_comments($_POST['comment']);since your post variable is called "comment" not "comment_text".Try:
And about the GET + POST thing: I don't know that there is anything inherently wrong with it... I've just never seen it before. I figured I'd ask.
You should post the error.
Also, it seems you're sending GET and POST data in the same request... why?
EDIT: Just looking at you code, I'd say
$comment = sanitize(strip_tags($comment));is your problem. PHP doesn't have a "sanitize" function. You probably want just$comment = strip_tags($comment);Obfuscate before going to production. Obfuscated code in development is silly.
If you do go the University route, don't just waste the spare time you'll have. Work on your own projects or start freelancing in your free time. Too many people think that their degree entitles them to a job, when really all it does is open a few more "prestigious" doors for you (that is, lets you confidently apply for jobs that 'require' a bachelors degree). Having a portfolio of works along with your degree is what really matters. It shows potential employees that you put in the time at University and got your degree, but you also went above and beyond your degree and learned/worked on some 'real' stuff.
At first I read "Codenade" as (phonetically) "colon-ade"... I almost threw up a little.
Convert it to a WordPress theme. It's not terribly complicated to do, but it will probably take you a while the first time to get it all right.
Here's a tutorial to get you started.