Would this send me into an infinite loop?
To execute it only once if you leave out the “return header” but how to get back to the htm file from the php?
It won’t loop. The simple.htm will do nothing, unless there are some inputs and submit button then it will wait until the user submits the form, then it will go to simple.php, and the redirection ( header(“Location:”) ) will take the user back to simple.htm and wait for another input. And as fellgal said, you need to check the $_POST data in your simple.php, otherwise anyone can call simple.php directly from the browser which runs the process in it.
Nope thats a terrible terrible idea. What you are doing is mixing domain/business logic with presentation logic, it is considered one of the worst software/application design practices.
Yeah MVC is a really good idea to go with, but even if you are using other architecture design patterns like MVP or MVVM you separate business logic from presentation as well. Combining HTML presentation with PHP mysql data access code is always a poor programming practice, even procedural programmers nowadays dont do this anymore.
I dont think newbies should be treated that much differently, once a bad habit forms its difficult to change. A newbie who gets used to coding by mixing business logic and presentation will have hard time separating job in future. At least, there is absolutely no need to tell a newbie who already write his/her program with good habits to go back to the bad programming practices. I mean, why tell a newbie who knows the idea of separation of concerns/responsibility not to do this? Why hold them back just because they are newbies?
I dont think newbies should be treated that much differently, once a bad habit forms its difficult to change. A newbie who gets used to coding by mixing business logic and presentation will have hard time separating job in future. At least, there is absolutely no need to tell a newbie who already write his/her program with good habits to go back to the bad programming practices. I mean, why tell a newbie who knows the idea of separation of concerns/responsibility not to do this? Why hold them back just because they are newbies?
Agreed, separation of concerns is an important concept that can be applied to procedural programming so why not teach and enforce it early.
Please be aware that the mysql_* extension is now deprecated as of the current version of PHP and will very likely be removed from the next 5.x version and will likely not be in PHP 6.x (when it eventually is released). You should migrate over to either the mysqli_* extension or to PDO. PDO is a better choice as it doesn’t tie you down so much to a particular database server software.
Once you have migrated you should use Prepared Statements to prevent SQL Injection attacks. Have a read of this article from the PHP manual, it shows how to use prepared statements with PDO and also explains the principle.