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%"> </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
Tell me how to create a text file in php?
How many types of inheritances used in php and how we achieve it.
What are properties in php?
What is session expiry?
What is scope of variable in php?
Does php support multiple inheritances?
What is difference between static and final in php?
Which will check if a function exists?
Which is not a php magic constant?
How to access a Static Member of a Class in PHP?
Do you know how to enable error reporting in php?
Is age a variable in research?
Explain what does the expression exception::__tostring means?
Which of the data type is compound datatype supported by PHP?
Which is better get or post method?