Friday 26 July 2013

To validate email addresses in PHP 5.2 and above:

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { // invalid emailaddress }
More info here: Stack Overflow
Note: Godaddy uses PHP 5.3
To create a new record in a mysql database:

INSERT INTO table_name VALUES (value1, value2, value3,...)
If one or more fields are auto update, put NULL in the values list.
Else, use this syntax
INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...)
To submit a form using POST in jQuery (ajax), use the post method:
jQuery.post( url [, data ] [, success(data, textStatus, jqXHR) ] [, dataType ] )

http://api.jquery.com/jQuery.post/
In Javascript, to redirect the browser to another page:
window.location.href = "http://site.com/new_url";

Thursday 25 July 2013

PHP Error Reporting

Put this code on the top of the php page to get error messages. Disable before going live.

error_reporting(E_ALL); ini_set('display_errors', '1');