PHP/MySQL Tutorial Part 3 – Insert Records

After connecting to the database (see older post PHP/MySQL Tutorial Part 2), the next step would probably be inserting data into it.

It is actually pretty simple.  The steps are:

1. Connect to the database
2. Select the right table
3. put the data in

You would need to setup a form on your website.  Let’s start with a simple one which contains name and email addresses only.  Use “POST” and when the form is submitted, send the data to “insert.php”.

And in insert.php, first use “POST” to gather the data, then use the following SQL statement:

$sql = “INSERT INTO table_name (name,email) VALUES ($name, $email)”;
$result = mysql_query($sql);

That’s done.  Simple is it?

 

Tags: , , , ,

This entry was posted on Monday, February 9th, 2009 at 12:40 am and is filed under PHP MySQL. You can follow any responses to this entry through the RSS 2.0 feed. Responses are currently closed, but you can trackback from your own site.

Comments are closed.