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 insert, update data in database

Answer Posted / sekar

here am creating 6 script
1.form.php
2.formaction.php
3.edit.php
4.delete.php
5.update.php
6.updateaction.php

1.form.php
<html>
<head>
<title>EMP Details</title>
</head>
<body>
<FORM METHOD=POST ACTION="formaction.php"
enctype="multipart/form-data">
<TABLE border="0" cellpadding="0" cellspacing="0"
width="500">
<TR>
<TD>Name :</TD>
<TD><INPUT TYPE="text" NAME="name"></TD>
</TR>
<TR>
<TD>Age :</TD>
<TD><INPUT TYPE="text" NAME="age"></TD>
</TR>
<TR>
<TD>Salary :</TD>
<TD><INPUT TYPE="text" NAME="salary"></TD>
</TR>
<TR>
<TD colspan=""2><INPUT TYPE="submit"
value="submit" name="submit">&nbsp;&nbsp;<A
HREF="edit.php">EDIT</A></TD>
</TR>
</TABLE>
</FORM>
</body>
</html>


2.formaction.php

<?php
$con = mysql_connect("localhost","root","");
$db = mysql_select_db("test",$con);

$name = $_POST['name'];

$age = $_POST['age'];

$salary = $_POST['salary'];

$insert = mysql_query("insert into emp_tab
(name,age,salary) values ('$name','$age',$salary)");

if($insert)
{
echo "sucess";

echo "<br>";

echo "<A HREF='form.php'>back</A>";
}
else
{
echo "fail";

echo "<br>";

echo "<A HREF='form.php'>back</A>";
}

?>

3.edit.php

<?php
$con = mysql_connect("localhost","root","");
$db = mysql_select_db("test",$con);


$select = mysql_query("select * from emp_tab");

echo "<table border='0' cellpadding='0'
cellspacing='0' width='500'>";

while($sresult = mysql_fetch_array($select))
{
$id = $sresult['id'];
$name = $sresult['name'];

$age = $sresult['age'];

$salary = $sresult['salary'];

echo "<tr><td>$name</td><td>$age</td><td>$salary</td
><td><A HREF='delete.php?name=$name'>DELETE</A></td><td><A
HREF='update.php'>UPDATE</A></td></tr>";

}
echo "</table>";


?>

4.delete.php

<?php
$con = mysql_connect("localhost","root","");
$db = mysql_select_db("test",$con);

$name = $_GET['name'];
$delete = mysql_query("delete from emp_tab where
name = '$name'");
if($delete)
{
echo "sucess";

echo "<br>";

echo "<A HREF='edit.php'>back</A>";
}
else
{
echo "fail";

echo "<br>";

echo "<A HREF='edit.php'>back</A>";
}
?>

5.update.php

<?php
$con = mysql_connect("localhost","root","");
$db = mysql_select_db("test",$con);

$update = mysql_query("select * from emp_tab");
echo "<table border='0' width='600'>";
while($uresult = mysql_fetch_array($update))
{
$id = $uresult['id'];

$name = $uresult['name'];

$age = $uresult['age'];

$salary = $uresult['salary'];

echo "<tr><td><INPUT TYPE='text' NAME=''
value='$name'></td><td><INPUT TYPE='text' NAME=''
value='$age'></td><td><INPUT TYPE='text' NAME=''
value='$salary'></td><td><A HREF='delete.php?
name=$name'>DELETE</A></td><td><A HREF='updateaction.php?
name=$name'>UPDATE</A></td></tr>";
}
echo "</table>";
?>

6.updateaction.php

<?php
$con = mysql_connect("localhost","root","");
$db = mysql_select_db("test",$con);
$name = $_REQUEST['name'];
$age = $_REQUEST['age'];
$salary = $_REQUEST['salary'];
echo $uaction = mysql_query("UPDATE emp_tab SET age
= '$age',salary = '$salary' where name = '$name'");
if($uaction)
{
echo "sucess";

echo "<br>";

echo "<A HREF='edit.php'>back</A>";
}
else
{
echo "fail";

echo "<br>";

echo "<A HREF='edit.php'>back</A>";
}
?>

Is This Answer Correct ?    28 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are php magic methods/functions?

998


What is the use of ajax in php?

1001


Can we embedded directly PHP code into XHTML document? State Whether True or False?

1790


Explain the types of string comparision function in PHP

945


Hi this is amul jani here, i complied my graduation in B.com stream.. but as career i looking for PHP language.. to get shape my career. so is that possible to enter in IT world.. for me how much scope of develop my career in this field.. amul jani

2017


What is the most common http method?

1083


How do you identify independent and dependent variables in regression analysis?

949


What is isset function in php?

1180


Explain mail function in PHP with syntax?

1001


What is the use of explode() function?

1060


What is in a cookie?

960


What happens if an expected input field was not submitted?

962


what are interfaces and Abstart classes

1997


Tell me how can we pass the variable through the navigation between the pages?

987


How to check curl is enabled or not in PHP

1136