Some Mysql example code using php

With a Mysql database you have the database and then you can have multiple tables within the dtabase.

Connect to the database

<?php
// Database user details
$database 'database_name';
$username='user_name';
$host='usualy_localhost';
$password='your_password';

// Connect to the database using the details entered into the variable above
$conn mysql_connect("$host","$username","$password");

// If the connection can not be made print Could not connect MySQL
if (!$conn) die ("Could not connect MySQL");

// If the database could not be opened or found print Could not open database
mysql_select_db($database,$conn) or die ("Could not open database"); 
?>

This can be code can be shortened but this will work nicely; It is also a good idea to use this as a separate file and include it into you page as it can then be used on multiple pages without having to rewrite it every time.

Selecting the data from the table

<?php
$result
=mysql_query("SELECT * FROM table_name") or die (mysql_error());
?>

This will select all the data from the table called table_name and if there is an error it will print it.

<?php
$result
=mysql_query("SELECT item1, item2 FROM table_name") or die (mysql_error());
?>

This will only select the information in the item1 and item 2 columns from the table called table_name and if there is an error it will print it.

<?php
$result
=mysql_query("SELECT * FROM table_name") or die (mysql_error());
?>

This will select all the data from the table called table_name and if there is an error it will print it.

<?php
$result
=mysql_query("SELECT * FROM table_name ORDER BY id") or die (mysql_error());
?>

This will select all the data from the table called table_name, order it by the data in the id column and if there is an error it will print it.

<?php
$result
=mysql_query("SELECT * FROM table_name WHERE id = '10'") or die (mysql_error());
?>

This will select all the data from the table called table_name where the id column contains the value of 10 and if there is an error it will print it.

Delete some data from the table

<?php
$result
=mysql_query("DELETE FROM table_name WHERE id = '10'") or die(mysql_error());
?>

This will delete all the data from the table called table_name where the id column contains the value of 10 and if there is an error it will print it.

Update some data in the table

<?php
$update 
mysql_query(" UPDATE table_name
SET item1='$item1', item2='$item2' WHERE id = '10'"
)
or die(
mysql_error());
?>

This will change the values of item1 and item2 to the values contained in the variables $item1 and $item2 in the table called table_name where the id coulumn contains the value of 10 and if there is an error it will print it.