Archive image

Posts Tagged ‘php’

Simple AJAX Unit Converter

I’ve been doing quite a bit with jQuery and AJAX as of late and have not only been impressed at the ease of implementation, but also the snappy and responsive feel that it brings to your web apps.

To demonstrate this I’m going to show you how to make a simple unit converter, which will allow you to convert units of digital storage without having to make a single page refresh.

Here’s a demo of what we’ll end up with.

Read more…

How to tell if a form has been submitted using PHP

Consider this scenario:

You have a form which submits to itself (e.g. a simple contact form). The first time it loads you don’t want to do anything other that render the form.

However, when a user hits “Submit”, you want to process whatever data you have received, then re-render the form, including (for example) error messages where appropriate.

Read more…

PHP – header(‘Location: …’) not working in MAMP

Recently, I was trying to help someone build a simple contact form in PHP.

This person was running everything locally in a MAMP server (Macintosh, Apache, Mysql and PHP) and everything was going swimmingly until we ran into a strange issue: PHP’s header('Location: ...') wasn’t working as expected. In fact, to be fair, it wasn’t working at all.

This is how we solved the problem.

Read more…

How to make a simple visitor counter using PHP

Imagine you want a visitor counter on your homepage. Sure, there are plenty of free ones out there, but I’m never happy about embedding third party code in my website, and besides wouldn’t it be more fun to make your own?

Of course it would!

Read more…

How to insert the current date into a DATETIME field in a MySQL database using PHP

This is a simple but effective tip that I picked up this week.

In the past, if I wanted to insert the current date into a table in a MySQL database from within a PHP script, I would always do something like this:

Read more…

Simple form validation in PHP

Server-side validation of user input is something you run into once in a while and although it is not an overly complicated subject, there are a couple of gotchas to be aware of.

This blog post examines how to validate a simple form in PHP.
First we need a form. It could look something like this:

Read more…

Inspect object in PHP

To display the contents of an object in ruby is really simple.
All you do is store the object in a variable, then pass the variable as an argument to the Kernel method p(), which in turn writes obj.inspect to the standard output.

Read more…