Enter Keyword Hear for Search This Blog

Saturday, 23 April 2016

How to insert,delete and select data from database using php

insert.php

<html>
<body>
<form action="insert_pro.php" method="post">
Name :<br />
<input type="text" name="nm" />
<br /><br />

Salary :<br />
<input type="text" name="sal" />
<br /><br />

<input type="submit" value="Insert">
</form>
</body>
</html>

insert_pro.php

<?php
$nm=$_POST['nm'];
$sal=$_POST['sal'];

$link=mysql_connect("localhost","root","") or die("can't connect");

mysql_select_db("employee",$link) or die("Wrong Database");

$q="insert into emp
(nm,salary)
values('$nm',$sal)";

mysql_query($q,$link) or die($q);

header("location:view.php");
?>

view.php

<html>
<body>
<table border="1" width="50%" align="center">
<tr>
<th>No</th>
<th>Name</th>
<th>Salary</th>
<th>Delete</th>
</tr>

<?php

$link=mysql_connect("localhost","root","");

mysql_select_db("employee",$link);

$q="select * from emp";

$res=mysql_query($q,$link);

while($row=mysql_fetch_array($res))
{
echo '<tr align="center">';
echo '<td>'.$row['id'].'</td>';
echo '<td>'.$row['nm'].'</td>';
echo '<td>'.$row['salary'].'</td>';
echo '<td><a href="delete_pro.php?no='.$row['id'].'">X</a></td>';
echo '</tr>';
}
?>
</table>
</body>
</html>

delete_pro.php

<?php
$id=$_GET['no'];

$link=mysql_connect("localhost","root","");

mysql_select_db("employee",$link);

$q="delete from emp where id=$id";

mysql_query($q,$link);

header("location:view.php");
?>

No comments:

Featured post

what is ajax?how to create ajax with php code

Ajax Introduction -  એજેક્સ નો ઉપીયોગ કરી ને તમે પેજ લોડ કાર્ય વિના બધી માહિતી મેળવી શકો.એજેક્સ થી તમે કોઈ પણ ડેટા ઝડપ થી મેળવી શકો છો...