Tag Archive - application

Connecting To A mySQL Database Using PHP

Connecting to a mySQL database is a very important part of any PHP application. mySQL has become an integral part of many PHP applications since it is also free to use. Connecting to a mySQL database only requires a single function call.

<?
$resource = mysql_connect( $server, $username, $password );
?>
  • $resource – The variable that the connection will be stored and passed to the other mySQL functions that are going to be called.
  • $server – The address of the database server.  Remembering that this is relative to the server, not your end machines.  For example, if your database server is located on the same machine as your webserver, this will be “localhost”.  If it is in the same datacenter (or network) it could be an ip address like 10.xxx.xxx.xxx or 192.xxx.xxx.xxx.  Otherwise you can use an entire URL like db.mydatabaseurl.com.
  • $username – Username to use to login to the database server
  • $password – Password to use to login to the database server

Create Your First jQuery Plugin

Today is a big day. Up until now we have been using other people’s plugins to improve our web applications. Today we will create our own. It will be an incredibly simple plugin, but will build a foundation for creating more advanced plugins.

This plugin will require you to look at the following pages:

http://www.learnjquerynow.com/lib/addresshide/1.0/addresshide.js

http://www.learnjquerynow.com/demos/addresshide.php

The addresshide.js file contains the actual code for the jQuery Plugin. The php file is our implementation test. What our plugin will do is hide an email address from spam crawlers. It does this by taking in a series of arguments and simply concatenating them together to create a single string. You could do this with simple jQuery or JavaScript code but why not create a plugin? It is a useful function that you will could use over and over again in many different projects.

So on to the explanation of the code.

In the plugin you will notice that there really is not much code here. The most important part of this file is the jQuery.extend({}) line. What this does is tells jQuery that this code is an extension. You will notice that we are using jQuery instead of $. This is because there are other JavaScript libraries use the $ function and this will force the JavaScript to use the jQuery object.

Inside of the extend function you will notice addresshide: function(options) {}. This is the name of our function that is going to be called. This function will be called in the format $.addresshide(opts).

The options parameter is actually a JavaScript object. It contains the following values:

name - The username of the email address (The “josh” in josh@notarealaddress.com)
separator - The separator of the email address (The “@” in josh@notarealaddress.com)
domain - The separator of the email address (The “notarealaddress” in josh@notarealaddress.com)
tld - The separator of the email address (The “com” in josh@notarealaddress.com)
write - This is a boolean value that when true, writes the created email address out using document.write command
selector - This is a string value that places the created email address in selector provided.

Now you can take a look at the PHP file and see how the plugin is utilized. You simply call it using the code described above, giving it the options required and you have yourself your first plugin.

What I would recommend is creating your own “jQuery” library that is your own personal toolbox of things that make your life easier.

Basic Form Validation Using The jQuery Validation Plugin

Form validation is a very important part of any web application. You have to make sure that your users are going to enter a numerical value when they put data into a quantity field (You don’t want them to enter “one” into a quantity field, unless of course you want to try and handle that kind of input). However it goes much deeper than just requiring a number. You have phone numbers, URL’s, email addresses, numbers that can’t be negative. It goes on and on.

jQuery has a plug in that will handle all your form validation needs. It is called the jQuery Validation Plugin. It is once of the earliest plug ins that were developed for jQuery. What it allows you to do is define what form elements needs to be validated, how to validate the element, and what to do if the element is invalid.

This post has an accompanying demo that can be found here.

Hot Linking The jQuery Validation Plugin

Microsoft allows hot linking of the Validation Plugin so you do not have to host the library. The URL of the plugin is: http://ajax.microsoft.com/ajax/jquery.validate/1.5.5/jquery.validate.min.js

Basic Validation

This form has very basic validation. It is ideal if you want quick and dirty validation of a form. All you have to do is put your validation rules into the class attribute for your form input elements (there are some other elements that these can go into). The form is automatically validated when the form submit button is clicked, but before the form is actually submitted.

In the example, the required value in the class attribute specifies that the field is required. Any value inside of the element is acceptable. It just cannot be blank. The email value in the class attribute requires that the value in the input field be an email address. The url value in the class attribute requires that the value in the input field be formatted as an URL (complete with the http:// at the beginning)

Some of the basic validation can take place outside of the class attribute. These tend to go inside of their own attributes on the input element. For example, the minlength attribute. The minlength attribute, specifies that the input tag be a specific length.

jQTouch – Building iPhone Web Applications without the Apple SDK

Let’s face it. The Apple iPhone is a huge success. It is the smart phone of choice for over ten million people worldwide. Despite the fact that the iPhone comes with the Safari Web Browser that renders the web flawlessly, there is still a very large need for dedicated web based applications for the iPhone.

With such a popular platform out there, knowing how to develop for the platform just makes sense. However, Apple does not make it easy for you to create iPhone Web Applications if you do not own a Mac (which despite how popular Apple is, most people out there do not own a Mac). So us Windows people are basically out of luck. That is until, jQTouch came on the scene. jQTouch makes it possible to create iPhone web applications without the need to use Apple’s API or development tools. jQTouch is a jQuery plug in that makes this all possible.
Continue Reading…

Advanced jQuery Ajax Options

Yesterday we discussed how you can use jQuery as an Ajax library for your web application. The discussion only covered the most basic options to make the Ajax work. There are many more options available to modify how the Ajax behaves. Today we will discuss those options.
Continue Reading…

Page 1 of 212»