Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

how to store date to database

Answer Posted / kannan

Step for store data to database
1.insert.php
2.insert_ac.php
3.edit.php
4.delete.php
5.update.php
5.update_ac.php

1insert.php
<?php
$con = mysql_connect("localhost","root","") or die("could
not connect".mysql_error());
$db = mysql_select_db("sekar") or die("could not select
db".mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div align="center" style="float:left;width:400px;">
<form method="post" action="insert_ac.php">
<table border="1" cellpadding="10" cellspacing="4" width="400">
<tr>
<td colspan="3" align="center" width="100%">Enter Customer
Infomation</td>
</tr>
<tr>
<td align="left" width="40%">Name</td>
<td align="center" width="10%">:</td>
<td align="left" width="50%"><input type="text" name="name"
/></td>
</tr>
<tr>
<td align="left" width="40%">Last Name</td>
<td align="center" width="10%">:</td>
<td align="left" width="50%"><input type="text"
name="lastname" /></td>
</tr>
<tr>
<td align="left" width="40%">Email</td>
<td align="center" width="10%">:</td>
<td align="left" width="50%"><input type="text" name="email"
/></td>
</tr>
<tr>
<td align="left" width="40%"><input type="submit"
value="SUBMIT" name="submit" /></td>
<td align="center" width="10%">&nbsp;</td>
<td align="left" width="50%"><a href="edit.php"
target="_blank">Edit</a></td>
</tr>
</table>
</form><br /><br />
<ul>
<li><a href="insert.php">Add New record</a></li>
<li><a href="edit.php">View record</a></li>
</ul>

</div>

</body>
</html>

2.insert_ac.php
<?php
$con = mysql_connect("localhost","root","") or die("could
not connect".mysql_error());
$db = mysql_select_db("sekar") or die("could not select
dn".mysql_error());

$name = $_POST['name'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];

$sql = "insert into test_mysql(name,lastname,email)
values('$name','$lastname','$email')";
$result = mysql_query($sql);
if($result!=""){
echo "Record successfuly added"." "."<a
href='insert.php'>Back</a>";
}
else{
echo "failed";
echo "<br>";
}
?>
<ul>
<li><a href="insert.php">Add New record</a></li>
<li><a href="edit.php">View record</a></li>
</ul>
3.edit.php
<?php
$con = mysql_connect("localhost","root","") or die("could
not connect".mysql_error());
$db = mysql_select_db("sekar") or die("could not select
db".mysql_error());

$sql = "select * from test_mysql";
$result = mysql_query($sql);
echo "<table border='1' cellpadding='10' cellspacing='4'
width='400'>";
while($res = mysql_fetch_array($result)){
$id = $res['id'];
$name = $res['name'];
$lastname = $res['lastname'];
$email = $res['email'];
echo
"<tr><td>$id</td><td>$name</td><td>$lastname</td><td>$email</td><td><a
href='delete.php?id=$id'>Delete</a></td><td><a
href='update.php?id=$id'>Update</a></td></tr>";
}
echo "</table>";
echo "<br>";
?>
<ul>
<li><a href="insert.php">Add New record</a></li>
<li><a href="edit.php">View record</a></li>
</ul>
4.delete.php
<?php
$con = mysql_connect("localhost","root","") or die("could
not connect".mysql_error());
$db = mysql_select_db("sekar") or die("could not select
dn".mysql_error());

$id = $_GET['id'];

$sql = "delete from test_mysql where id='$id'";
$result = mysql_query($sql);
if($result!=""){
echo "Record successfuly delete"." "."<a
href='edit.php'>Back</a>";
}
else{
echo "failed";
echo "<br>";
}
?>
<ul>
<li><a href="insert.php">Add New record</a></li>
<li><a href="edit.php">View record</a></li>
</ul>
5.update.php
<?php
$con = mysql_connect("localhost","root","") or die("could
not connect".mysql_error());
$db = mysql_select_db("sekar") or die("could not select
dn".mysql_error());

$id = $_GET['id'];
$sql = "select * from test_mysql where id='$id'";
$result = mysql_query($sql);
echo "<form method='post' action='update_ac.php?id=$id'>";
echo "<table border='1' cellpadding='10' cellspacing='4'
width='400'>";
while($res = mysql_fetch_array($result)){
$id = $res['id'];
$name = $res['name'];
$lastname = $res['lastname'];
$email = $res['email'];

echo "<tr><td><input type='text' name='id'
value='$id'></td><td><input type='text' name='name'
value='$name'></td><td><input type='text' name='lastname'
value='$lastname'></td><td><input type='text' name='email'
value='$email'></td><td><input type='submit' name='submit'
value='submit'></td></tr>";
}
echo "</table>";
echo "</form>";
echo "<br>";
?>
<ul>
<li><a href="insert.php">Add New record</a></li>
<li><a href="edit.php">View record</a></li>
</ul>
6.update_ac.php
<?php
$con = mysql_connect("localhost","root","") or die("could
not connect".mysql_error());
$db = mysql_select_db("sekar") or die("could not select
dn".mysql_error());

$id = $_REQUEST['id'];
$name = $_REQUEST['name'];
$lastname = $_REQUEST['lastname'];
$email = $_REQUEST['email'];

$sql = "update test_mysql set id='$id', name='$name',
lastname='$lastname', email='$email' where id='$id'";
$result = mysql_query($sql);
if($result!=""){
echo "Record successfuly updated"." "."<a
href='edit.php'>Back</a>";
}
else{
echo "failed";
echo "<br>";
}
?>
<ul>
<li><a href="insert.php">Add New record</a></li>
<li><a href="edit.php">View record</a></li>
</ul>

Is This Answer Correct ?    0 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Tell me how to create a text file in php?

931


How many types of inheritances used in php and how we achieve it.

898


What are properties in php?

922


What is session expiry?

897


What is scope of variable in php?

999


Does php support multiple inheritances?

950


What is difference between static and final in php?

963


Which will check if a function exists?

1026


Which is not a php magic constant?

1015


How to access a Static Member of a Class in PHP?

971


Do you know how to enable error reporting in php?

922


Is age a variable in research?

847


Explain what does the expression exception::__tostring means?

818


Which of the data type is compound datatype supported by PHP?

954


Which is better get or post method?

871