Sending dynamic data to server and back in flash

This tutorial shows how to send data from flash to php then change the data and send back to flash using LoadVars.

First the actionscript that is ran from the frame:

var retrieveLoadVars:LoadVars = new LoadVars();// setup object to catch data from remote file
var sendLoadVars:LoadVars = new LoadVars(); // setup object to send data to remote file
retrieveLoadVars.onLoad = function(success) // call function when data is loaded
{
if(success) //function to run if data has been loaded
{
trace(retrieveLoadVars.name1);// print out results to the output window
trace(retrieveLoadVars.name2);// print out results to the poutput window
} else //data not loaded
{
trace(”error”);// print out error to the poutput window
}
}
sendLoadVars.param1 = “flash”;//send … Continue Reading

Upload files and add them to a database with PHP and MySQL

Upload files and add them to a database with PHP and MySQL

This tutorial will show you how to upload a file and add it to a database.

At the very top of the page connect to your database here’s a simple way of doing it just change the db properties with your own, in a live site the db details would normally be in a standalone file and then included into all pages then need it…. Continue Reading

Delete rows from a MySQL database with a confirmation

Delete rows from a MySQL database with a confirmation

This tutorial shows you how to delete rows from your database and uses a JavaScript powered confirmation basically when you press delete a confirmation message will appear asking if you want to delete then item making sure you meant to delete it.

For this example lets say I have a news table with lots of news in it in the structure of newsID, newsTitle and newsContent.

what were going to do is build a page that lists all the news items with their newsID and newsTitle and in that list will be a link … Continue Reading

Limit the amount of characters from a MySQL Query

Tutorial to limit the amount of characters from a MySQL query.

You can limit the amount of characters that come out of a query quite easily with the function SUBSTRING().

For example say you were printing out news items but only wanted a short amount of text say 200 characters you would do this by issuing the command SUBSTRING(first charactor, last character) giving it the start position and the end position of text to bring out.

Lets do it in a working example:

This is a standard MySQL query first I add a variable to run the query then using mysql_query to actually run … Continue Reading

Login Script with Validation

A login script tutorial to log users into your database driven site using sessions

The database structure I’ll be using in this example is below.

CREATE TABLE IF NOT EXISTS `members` (
`memberID` int(11) NOT NULL auto_increment,
`username` varchar(50) NOT NULL,
`password` varchar(32) NOT NULL,
PRIMARY KEY (`memberID`)
) ENGINE=MyISAM;

Make a connection to the database… Continue Reading

Change file permissions dynamically with php

A tutorial to change file permissions dynamically with php

first define the function name in this case call it changePermissions with two parameters $path is the path to the folder and $modlevel is the permissions level to use.

Then using the command chmod we change the file permissions

then do an if statement to see if it’s worked or failed this is optional

to run the function you need to call it, you call it by typing it’s name with the parameters

here’s the full script:

That’s it now you … Continue Reading

Split a string into parts using explode

A tutorial to split a string into parts using explode.

The code that will run to split the string into parts will be encased inside a function, start the function by using the word function followed by it’s name in this case stringparts pass 2 parameters with it in parenthesis $parts and $times, $parts is the string to be split and $times is the number of times to split the string.

Then use explode to split the string and add it to a variable, to explode the string using the word explode followed by 3 properties the fist tells … Continue Reading

Delete folders from server using PHP

A tutorial to create a function to delete folder and all sub folders from the server.

start by stating it’s a function by issuing the word function followed by a name in this case delete_directory with a parameter this is a variable that contains the name of the directory you want to delete

Then an if statement is used to see if the directory is a real directory and if it is then open the directory

then anther if statement is done to see if the directory is valid if it’s not then return false is … Continue Reading

Motion tween with actionscript

If you ever wanted to do a motion tween with actionscript this tutorial will be very useful.

The actionscript goes in the frame. Make a button in my example I gave it an instance name of bt.

make a movieclip of the item you want to tween give it an instance name in my example i have given it a name of a1

// button has an instance name of bt when it’s pressed the tween is performed

bt.onPress = function() {
// call function to do the tween
Continue Reading

Custom error pages with htaccess

A tutorial to enable custom error pages with an htaccess file. Note htaccess files only work on a linux server

To create an htaccess file open notepad or any plain text editor and save the file as .htaccess, if using notepad make sure the file type is set to all files or you will create a txt file.

There are five types of error pages that your server has to offer which are:

400 - Bad request
401 - Authorization Required
403 - Forbidden directory
404 - Page not found
500 - Internal Server Error

if you don’t have the right page like say a 404 page … Continue Reading

Override file upload sizes an htaccess file

A tutorial to override file upload sizes an htaccess file. Note htaccess files only work on a linux server

By default you can only upload files up to 2MB in file size but this can be increased with an htaccess file.

To create an htaccess file open notepad or any plain text editor and save the file as .htaccess, if using notepad make sure the file type is set to all files or you will create a txt file.

start with php_value which tells the server to expect a rule to follow

To increase the file size that can be uploaded use the rule … Continue Reading

Disable directory browsing

A tutorial to disable directory browsing with an htaccess file. Note htaccess files only work on a Linux server

Letting people snoop around your directory’s that don’t have an index file in them can lead to security vulnerabilities. thankfully their is a simple solution to this problem by using an htaccess file.

By disabling directory browsing a user would see a forbidden page rather then the files inside that directory.

To create an htaccess file open notepad or any plain text editor and save the file as .htaccess, if using notepad make sure the file type is set to all files or you … Continue Reading

Edit data from a database

A tutorial to edit existing data from a MySQL database.

Before you can edit any data you need to select it you can select the item to be edited by using it’s ID from the table it is in.

You can either manually input the ID into the query to retrieve the data or use a variable to store the ID in, this is a better option as you can use the page edit script to edit all items for the same table without having to modify anything.

To store the ID into a variable on a page that lists the rows … Continue Reading

Show all MySQL databases and tables

Want to see what databases you have and what tables are inside each database but do not have access to phpmyadmin or similar program?

Luckily mysql has some built in functions that enable you to see your databases and tables easily.

Let me take you through it.

First make a connection to your database server… Continue Reading

Naming your sessions

In PHP when you create a session and give it a name always make the name unique and not the same name as any variables you have.

For example if you create a session like this:

You could override the session with the variable username a common example of this is if you had a list of user and had a query pulling out all the usernames from your database the loop would cause the last username in the loop to override the session, In this case the session is now the last user in the … Continue Reading

CSS for different versions of IE

CSS for different versions of IE

Some times your site looks different in IE 6 then it does in 7 or in Firefox. Most of the time you can combat this with better coding but there’s times when that just not enough.

in them situations you can use condition statements for IE6 & IE7 in these conditions you would ran an alternate version of your CSS code an example of this:

This would be placed in between the head tags

if lte IE 6 means if the browser is … Continue Reading

Styling forms with CSS

Forms come in all shapes and sizes but they all look the same and as such they all look really dull but you can change that by styling them with CSS so they match the theme of your site.

You can add styling to your form elements by using id for that element but you can only use that style once per page a better way of doing it is to using a class then you can have the style on the same page as many times as you like.

You can also style a form by assigning a style to the … Continue Reading

Registration script with Validation

In this tutorial I will explain how to create a user registration script along with validation.

When ever you collect data from users you always have to validate all the data NEVER trust anything from a user!

To store the member info into a database table you need to create the table first here is the structure of the table you can create this in phpmyadmin or script it yourself… Continue Reading

Searching with PHP and MySQL beyond LIKE

Ever wanted to add a search feature to your php & MySQL driven web site? Then your in luck this tutorial shows you how!

This tutorial assumes you already have a MySQL database and a table with some data already in your table. This tutorial also assumes your familiar with basic php syntax.

You can search your MySQL database in many ways the most common way is using the command LIKE eg. LIKE ‘$search’ which would search for a word like the one you entered into the search field the problem with this is if your search term is not exactly the … Continue Reading

Switch Statement

From time to time you may need to find a value of a variable to perform an action you can do this with an if elseif else statement but its much more efficient to use a switch statement to do the same thing.

Using a switch statement means less code and easier to read.

In this example I have created a variable called $mydata which contains a value of 2 using the assignment operator.

Then I start the switch statement using switch() for switch to work it needs a variable parameter in this case am using $mydata then open … Continue Reading

Magic Quotes

This tutorial will explain what magic quotes are and how to use them

When Magic Quotes are enabled will automatically escape single and double quotation marks.

This helps prevent problems in php/html.

There are two types of Magic Quotes:

magic_quotes_gpc which works for forms, urls and cookies (gpc stands for get, post and cookie).

magic_quotes_runtime which works for data from external files and databases.

If there is an apostrophe like: dave’s then the result would be daves to get round this you can use the function stripslashes() This function removes any backslashes found…. Continue Reading

PHP Redirect

Tutorial on PHP redirect to be redirected to another page or web site

For this tutorial lets suppose you have moved your web site to another domain and want your visitors to be redirected to your new domain you can use PHP for this purpose.

Here is the code to redirect a user:

Contact Form

Need a contact form for your site? This tutorial shows you how to create one.

This tutorial assumes you have a basic knowledge of PHP there are other tutorials on this site that explains some of the mechanics used here.

The contact form will be sent to your email address once the form is completed.

First we check that the form has been submitted:

If the form has been submitted we check to make sure the fields are not empty and trim any white space.

We first check the name field … Continue Reading

If statements

An introduction to if statements and else statements

When your interacting with php from time to time you may want to show something else depending on a condition this is very simple to do using if and if else statements.

The syntax for an if statement goes like this:

then this can include an else statement

This can be expanded further using an ifelse statement:

In the first example if (condition) { means in … Continue Reading

Sticky Forms with PHP

Ever submitted a form and not filled in all the field only to have to fill them all in again? This tutorial shows you how to keep your inputted data.

To keep the inputted data in a input field have the value call the php variable for it like this:

Here is a simple form with sticky input:… Continue Reading

Using the Rand() function in PHP

This tutorial introduces you to the function rand()

MySQL has many built in functions one of which is called rand() which is short for random. From time to time you might want to display some results from your database in a different order and here’s where the rand() function comes into play.

For this example I will randomly show a different banner from my database.

Each time the page loads up I want a different banner to be shown and not in any order you would start with a normal select statement and then add rand() in an order by statement: … Continue Reading

Limit MySQL output

This tutorial will show you how to limit how many results you get from a database query

This tutorial assumes you have an understanding of basic PHP syntax.

When your querying your database you may not always want to see all the results instead just see the last 5 results for example.

This is very simple to do using the LIMIT clause in MySQL.

Here’s an example

This will only show the last 5 results in descending order. By default MySQL … Continue Reading

Counting results in PHP

A basic tutorial to show you how to use php to count the number of results in a MySQL query

For this tutorial lets say you have a members site and would like to count how many members you have then print out the result.

This is very simple to do in php and there are lots of way to do it. This is a simple way of counting the members in your database.

Here’s the code to count all members in your members table:… Continue Reading

Including files

Including files with php is very easy to do. This tutorial shows you how.

The main reasons why you might use php includes/require one of these reasons is to include the footer in to every page but only have one footer.

Let me explain you create a new file in can be a .html or .php extension either will work I always choose .php extension as I usually has some php running even in the footer.

In your new file save it as footer.php and in the file only have what you want in the footer do not put in the doc type … Continue Reading

Viewing data from a database

A tutorial on viewing data from a database

There are many ways to retrieve data from a database this tutorial will show you a popular way of selecting the data you want and then printing it to the page.

This tutorial assumes you have a basic knowledge of PHP

To start off include your database connection details

Select what you want to display from the database to select everything use * which stands for ‘All’

If you wanted to select certain fields you can specify them like: … Continue Reading

Inserting data into a database

A tutorial on inserting data into your database.

This tutorial assumes you have basic knowledge of PHP and you have access to a MySQL database. Also you can connect to your database.

Here is the table structure I will be using for this tutorial.

For this tutorial I’m going to create a form to insert news items into the news table you will need to change the variables to match your own.

First connect to your database: … Continue Reading

Creating a table within a database

This tutorial will explain how to create a users table in your database.

This tutorial will assume you know how to connect to the database.

the

is a comment which php will ignore. The comment is there for your own reference.

The include function will include the database connection details

to include the database details php needs to know where to find the file. We will let php know the address of the file with the globel variable

which will get the address from the start of the server ie the domain name www.example.com

Since we connecting a global variable with … Continue Reading

Javascript Redirect

This tutorialwill show you how to redirect your page with javascript.

first you need to tell the browser your using javascript by using

Which tells the browser your using text with javascript you then use the window property and location to specify an address to use

window.location = “http://www.webguideuk.com/”

then close the javascript

Here’s the full script

window.location = “http://www.webguideuk.com/”

Connecting to a database

This tutorial will explain how to connect to your database.

First open a text editor such as Notepad or Dreamweaver..ect

To start a php page you need to declare your using php. To do this you write the php open tag… Continue Reading