Connection with Database...(name it as connection.php)
<?php
$servername="localhost";
$username="root";
$password="";
$databasename="actual_db";
?>
For Delete an Entity... (delete.php)
<?php
include ("connection.php");
$connect=mysql_connect($servername,$username,$password);
$select_db=mysql_select_db($databasename);
$strquery=" DELETE from records_table where id = '" . $_GET['id'] . "' ";
$results=mysql_query ($strquery);
echo 'Delete Successfull!!';
header ('location: https://127.0.0.1/ACTUAL/MAIN.php ');
?>
Edit....(edit.php)
<?php
include ("connection.php");
$connect=mysql_connect($servername,$username,$password);
$select_db=mysql_select_db($databasename);
$strquery = "SELECT * from records_table where id= '" . $_GET["id"] . "' ";
$results = mysql_query ($strquery);
$row = mysql_fetch_array($results);
?>
<body>
<form id="form1" name="form1" method="get" action="update.php">
<label>Name:
<input name="name" type="text" id="name" value=" <?php echo $row["name"]; ?>" />
</label>
<p>
<label>Section:
<input name="section" type="text" id="section" value=" <?php echo $row["section"]; ?>" />
</label>
<input name="id" type="hidden" id="section2" value=" <?php echo $row["id"]; ?>" />
</p>
<p>
<label></label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="Update" />
</label>
</p>
</form>
Main Page...... (main.php)
<!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=iso-8859-1" />
<title>Actual PHP</title>
</head>
<body>
<form id="add" name="add" method="get" action="SAVE.php">
<label>NAME:
<input name="name" type="text" id="name" />
</label>
<p>
<label>SECTION:
<input name="section" type="text" id="section" />
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="SAVE" />
</label>
</p>
</form>
<table width="749" border="1">
<tr>
<td width="289">Name</td>
<td width="214">Section</td>
<td width="57"> ID </td>
<td width="161"> Actions </td>
</tr>
<?php
include ("connection.php");
$connect=mysql_connect($servername,$username,$password);
$select_db=mysql_select_db($databasename);
$strquery="SELECT * from records_table";
$results=mysql_query($strquery);
$num=mysql_numrows($results);
$i=0;
while ($i< $num)
{
$f1=mysql_result($results,$i,"name");
$f2=mysql_result($results,$i,"section");
$f3=mysql_result($results,$i,"id");
?>
<tr>
<td><?php echo $f1 ; ?></td>
<td><?php echo $f2 ; ?></td>
<td><?php echo $f3 ; ?></td>
<td><?php echo " <a href='edit.php?do=edit&id=" . $f3 . "'> edit </a> "; ?> | <?php echo " <a href='delete.php?id=" . $f3 . "'> delete </a> "; ?></td>
</tr>
<?php
$i++;
}
?>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<form id="form1" name="form1" method="get" action="search.php">
<label>Search:
<input name="search" type="text" id="search" />
</label>
<p>
<label>
<input name="do" type="submit" id="do" value="Search" />
</label>
</p>
</form>
<p> </p>
<p> </p>
<p>
</p>
<p> </p>
<p> </p>
<p> </p>
</body>
</html>
Save (save.php)
<?php
include ("connection.php");
$connect=mysql_connect($servername,$username,$password);
$select_db=mysql_select_db($databasename);
$strquery="INSERT INTO records_table SET name= '" . $_GET['name'] . "', section= '". $_GET['section'] ."' ";
$results=mysql_query ($strquery);
header( 'Location: https://127.0.0.1/ACTUAL/MAIN.php' ) ;
?>
For Update...(update.php)
<?php
include ("connection.php");
$connect=mysql_connect($servername,$username,$password);
$select_db=mysql_select_db($databasename);
$strquery="UPDATE records_table SET name= '" . $_GET['name'] . "', section= '". $_GET['section'] ."' WHERE id='". $_GET['id'] ."' ";
$results=mysql_query ($strquery);
header ('location: https://127.0.0.1/ACTUAL/MAIN.php ');
?>
$strquery="UPDATE s_info SET SName= '" . $_GET['SName'] . "', SReg= '". $_GET['SReg'] ."',SAge='". $_GET['SAge'] ."',SHouse= '"
. $_GET['SHouse'] . "',STransport= '" . $_GET['STransport'] . "',SQuality= '" . $_GET['SQuality'] . "',SHome_City= '" . $_GET['SHome_City'] . "',
SPh_Number= '" . $_GET['SPh_Number'] . "',SE_Mail= '" . $_GET['SE_Mail'] . "',SB_of_Date= '" . $_GET['SB_of_Date'] . "',
SPortrait= '" . $_GET['SPortrait'] . "' where SRoll='".$_GET['SRoll']."'";
No comments:
Post a Comment