Get PHP MySQL Tools
at
iPage Affordable Web Hosting only $3.50/mo

PHP MySQL
Interactive Website Design

Inserting Data into a Table

The basic SQL syntax is placed within the mysql query function statement.

mysql_query ();

The SQL syntax is enclosed in double quotes. It supplies the command , the name of the table, the field names and the values to be added.

"INSERT INTO birthdays (name, birthday) VALUES ('Peggy', 'June4')"

The mysql_query function can be used in many other database operations.

The code for adding data to a table is shown below.

The first example (red) shows the actual VALUES which are added.

The second (blue) shows how to add data parsed from a simple form.

<?
$name=$_POST['name']; $birthday=$_POST['birthday']; $db="mydatabase";
$link = mysql_connect("localhost");
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
mysql_query ("INSERT INTO birthdays (name, birthday) VALUES ('Peggy', 'June4')");
mysql_query ("INSERT INTO birthdays (name, birthday) VALUES ('$name','$birthday')");
mysql_close($link);
?>

Download the Scripts

The Birthdays Database management files can be downloaded in a zip file. The package contains an integrated db management system, with a simple interface. This Instruction file is included in the download.
Download birthdays_db.zip

MySQL Tutorial

To extend your knowledge of MySQL study the Docs and Tutorials at the official MySQL website. MYSQL.com