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
What is "echo" in php?
Is array empty php?
Explain me how failures in execution are handled with include() and require() functions?
What is the difference between the include() and require() functions?
What is the array in php?
Which is not a file-related function in php?
What is cookie in php with example?
If we login more than one browser windows at the same time with same user and after that we close one window, then is the session is exist to other windows or not? And if yes then why? If no then why?
What is the difference between runtime exception and compile time exception?
How is session id stored in browser?
Which is the best php framework for a beginner?
Do you know how to declare an array in php?
What is php session_start() and session_destroy() function?
What is oops php?
What are the environmental variables?