Inserting Data in php MySQL database.

To inserting a data to database you have to create a database and a table in going to http://localhost/phpmyadmin..

suppose your database name is naogaon and table name is member with three fields number, name and address

then write the following code in a editor and save it as

//……………………insert.html……………………….\\

<form action=”Insert.php” method=”post”>
Number: <input type=”text” name=”M_number” />
Name: <input type=”text” name=”M_name” />
Address: <input type=”text” name=”M_address” />
<input type=”submit” />
</form>

now write another php code and save it as

//…………………insert.php……………………….\\

<?php
$con = mysql_connect(“localhost”,””,””);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}

mysql_select_db(“naogaon”, $con);

$sql=”INSERT INTO member (number, name, address)
VALUES
(‘$_POST[M_number]’,’$_POST[M_name]’,’$_POST[M_address]’)”;

if (!mysql_query($sql,$con))
{
die(‘Error: ‘ . mysql_error());
}
echo “1 record added”;

mysql_close($con)
?>

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: