Everything PHP: Queries

Published on Aug 13, 2009   //  Development

Everything PHP

We have now gone over how to connect to a database using PHP, as well as some of the essential SQL queries. Finally we can put these two lessons together and query the database within PHP. Executing queries in PHP versus directly to MySQL is more or less the same.

Before we can begin executing MySQL queries via PHP, we need to connect to MySQL and select our database. Please see that article for details on how to do that, as we are just going to be going over the querying part today.

To execute MySQL queries, we’ll be using the PHP function mysql_query(). Just as the name implies, this functions allows you to send SQL queries to the connected MySQL database. Let’s take a look at a basic example:

[php]mysql_query("SELECT [field_names] FROM [table_name]");[/php]

We encase the SQL query in double quotes (as opposed to single quotes) because we will need to use single quotes to wrap around values. Otherwise we would have to escape the single quotes each time, which is far from ideal. There is a glaring problem with the above code. If you were to make an error in your query, the function will not output an error (the function will return false), and any code relying on this query will not work correctly (which could be hard to debug).

The solution to this is to ensure that if mysql_query() returns false we stop the execution of the rest of the file, and output the error MySQL returned. We can use an or exit() statement and use the mysql_error() function to get the last error MySQL reported. Let’s look at the above example with this error handling added:

[php]mysql_query("SELECT [field_names] FROM [table_name]") or exit(‘A MySQL error has occurred: ‘ . mysql_error());[/php]

A quick note on exit(): The functions exit() and die() are equivalent and there’s no standard on which to use. As such, you’ll may see a different one than you are used to in other’s programming. Just wanted you to be aware.

If you which to use values (such as in a where clause), they must be encased in single quotes, even when you’re using a variable as the value.

When the MySQL query is successful, the function will return a resource. You’ll need to use some other functions to be able to handle and process a resource. Which is what we’ll be covering next week.

Marketing 101: Value in Newsletters

Published on Aug 13, 2009   //  Marketing Tips
Off

Despite newer options like Twitter and Facebook, email is still the preferred form of communication for a lot of people online. As such, email marketing is still very much alive and well, but you need to make use of this technique properly if you hope to use it as an effective means of attracting and retaining your customers. In this way, an email newsletter shouldn’t simply be one large advertisement for your company and its products; it needs to provide value to the subscriber.

This only makes sense, but who would want to subscribe to an email newsletter that is nothing more than a giant advertisement. There are different routes that you can take to add value to your newsletter while still retaining the marketable value of maintaining the email subscriber list. As is the case with this blog, it is possible to use the email newsletter as a repository of useful information related to your industry. If you are a real state agency, for example, you may want to have some useful articles included in your newsletter that discuss interior design and the process of buying a home.

Another option that may be even more effective in generating sales is to provide added value to subscribers in the form of exclusive discounts and coupons. By handing over their email address to you, subscribers are granted access to special sales and other discounts that are not available to the general public. For instance, I recently received a message from New York Fries that allows me to buy a regular size fries for just $1.25. This coupon is not be advertised or distributed anywhere else, so subscribers can feel special for receiving it.

Do you subscribe to any email newsletters? What made you subscribe to that newsletter over equivalent alternatives?

Community Poll

Published on Aug 12, 2009   //  Polls
Off

Last week we asked what type of WordPress development topics would you like to learn about and 56% said theme development. This weeks question is…

{democracy:91}

WordPress Wednesday: How to Report Security Bugs

Published on Aug 12, 2009   //  WordPress
Off

It seems like the WordPress development team comes up with a new version of our favorite CMS every few days. Some of these updated versions introduce new features or change some aspects of the administrative dashboard, but the vast majority of updates are released to address security concerns and other bug fixes. If you happen to come across a problem with WordPress, what is the best route of action?

I came across a blog post on WeblogToolsCollection.com that discusses this very concern. You see, one user came across a security flaw in WordPress and proceeded to discuss it openly and publicly with the rest of the WordPress community. Not surprisingly, a hacker caught wind of this flaw and proceeded to exploit it. For this reason, it is typically not the best idea to discuss security flaws quite so publicly.

Instead, in the interest of minimizing damage to the blogs in the community running the WordPress platform, it may be a better idea to discretely send an email to the security support team at WordPress. Their email address is security -at- WordPress -dot- org.

This way, a fix can be developed before the exploit becomes too well known in the hacker community. You can discuss the problem in private with some of your friends and colleagues, but making it public information could lead to even more problems.

Business 101: Above and Beyond

Published on Aug 11, 2009   //  Business Topics

It can be difficult to separate yourself from your competition, especially if you are offering seemingly the same kinds of products and services. What’s stopping your potential customer from going to the other guy across the street? What is it about your particular company that makes it more appealing to customers than your competition?

I was talking to a friend of mine who had recently moved to a new city for a new job and she needed several articles of clothing to be altered, hemmed, and dry cleaned. Shopping around, she found that the price for hemming a standard pair of dress pants was about the same at every location that she called, but then she came across an advertisement in the local newspaper for an alternation place that went above and beyond the call of duty.

Rather than getting you to come to their location to drop off your clothing, pay, and pick it up when it is ready to go, this place offered free pickup and drop-off service. There was seemingly no set minimum, but my friend did have about a half dozen items that needed to be altered. For this amount of business, the alteration place was more than willing to visit my friend at her apartment, take her measurements, pick up the clothes, and drop them off a few days later. There was no additional cost and this huge added convenience made the decision an easy one for my friend.

By going above and beyond the call of duty, this place was able to attract a fairly large order from my friend. This added touch of customer service left a good impression and now, even if she doesn’t need the pickup and dropoff service, my friend is more likely to return to this same tailor to get any future work done. Attract customers with a little something extra and it’ll pay off in spades in the long run.

Twitter For Business – Getting Results Seminar

Published on Aug 11, 2009   //  Events
Off

socialmediasml

More and more people are touting Twitter as a way to increase market share, branding and sales. The problem is no one is telling you how to do it. This seminar will show you how to create a following of users that will help your business grow.

In our previous session we covered off the basics of using twitter and why you should use it. This time were focusing on getting content into your twitter using multiple sources. We will cover tactics you can use to grow your followers. We will provide real world examples of how your business can grow on twitter and the right tools to get the job done.

If your on twitter or thinking about using twitter for your business you will find this seminar immensely valuable.

When is the event happening?
Wednesday, September 23, 2009 7:00 PM – 10:00 PM

Where is it happening?
To Be Determined – Cloverdale/Langley Area

Cost
This event is $75.

Registration
To register for this event RSVP here.

Page 5 of 7« First...34567