I was testing out a new Drupal project build and found this strange error when uploading files to nodes using the Upload module. This error produced a lot of warning messages that appeared on the screen (in the process alarming my project manager) but apeared to have no impact on the actual function of the module, or the file uploaded. Essentially, when a file was uploaded the following errors were produced.
The following code was executed.
If you have a large page or form that uses validation on it then you will probably want to tell the user that something is going on. One way to do this is by telling the user at the top of the page that something has gone wrong and then letting them figure out where.
A more elegant solution is to scroll the page down the just above the first error message so that the user is aware of what they need to fill in. This can easily be done through a combination of jQuery and the ScrollTo plugin.
There are numerous ways to print out dates and times, and many hours of programming are spent in converting dates from one format to another.
To do this in MySQL you use the STR_TO_DATE() function, which has two parameters. The first parameter is the time to be parsed and the second is the format of that time. Here is a simple example that converts one date format to a MySQL formatted date string.
NOTE: This bit of code is potentially very dangerous and should NOT be uploaded to your web host. I only use this function on my localhost to quickly check that a snippet of code works.
If you want to quickly run some PHP code, and don't want to have to go through creating a file just to see the outcome of a simple calculation is then this snippet might be of some use to you.
In my last post I talked about the PHP CodeSniffer, so today I thought I would solve a common problem that doesn't seem to have any documentation. Whilst correcting a class file I had there was this one warning that just wouldn't go away.
One of the biggest problems I have found with PHP is the reputation that it gets. This is due to the amount of abuse that the language undergoes by many developers every day. They write code that works, and is efficient, but trying to figure out what it does can take hours as there are no comments, and the code is generally written in any old way. PHP is quite lenient with regards to how code is written.
XDebug is an excellent debugging solution that will give you a more detailed indication of what is wrong in your code. Here is an example of trying to divide two variables that have a value of 0.
Having a testing server is quite a common practice, but what happens when you want to go live and you don't want all of your error messages displayed?
A good way of doing this is to create a variable that you can then use to detect what server your code is running on and set your error displaying accordingly. The following section of code will set a variable to true if the code is not running on the server name www.hashbangcode.com. This variable is then used to set the error reporting level.
Pinpointing where an error in a program is occurring is not always easy. This can be even more of a problem when you write an SQL query that produces an error. Take the following select statement, which is clearly wrong.