Sunday, November 11, 2012

update php form

category.php
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<ul>
<li><a href="update.php" float:right>Job Entry Form</a></li><li><a href="enter.php" float:right>Job Progress Update Form</a></li>
</ul>
</body>
</html> 



 config.php
<?php
$host = "localhost"; //database location
$user = "root"; //database username
$pass = ""; //database password
$db_name = "jobs"; //database name
//database connection
$link = mysql_connect($host, $user, $pass);
mysql_select_db($db_name);
//sets encoding to utf8
mysql_query("SET NAMES utf8");
?>


update.php
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<a href="category.php">category>></a><a href="update.php">enter>></a>
<?php
$id=$_GET['id'];
if(is_null($id))
$id=-1;
$_SESSION['id']=$id;
?>

<form action= "dbupdate.php" method="post" >
<center>
    <h2> Job Entry Form</h2><?php
    if($id==-1)
    {
   print "<table width=\"381\" border=\"0\">
     
      <tr>
        <td>Equipment</td>
        <td><input type=\"text\" name=\"equ\" id=\"equ\" /></td>
      </tr>
      <tr>
        <td>Deffect</td>
        <td><textarea name=\"deff\" id=\"deff\" cols=\"45\" rows=\"2\"></textarea></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><input type=\"submit\" value=\"Enter\" />
        <input type=\"reset\" value=\"Cancel\" /></td>
      </tr>
    </table>
    ";
    }
    else {
$connect = mysql_connect("localhost", "root", "") or
die ("check your server connection.");
mysql_select_db("jobs");
    $result=mysql_query("select * from job where id=".$id);
    while($row=mysql_fetch_array($result)){
        print "<table width=\"381\" border=\"1\">
     
      <tr>
        <td>Equipment</td>
        <td><input type=\"text\" name=\"equ\" id=\"equ\"  value=\""; echo $row['equ']; print "\"/></td>
      </tr>
      <tr>
        <td>Deffect</td>
        <td><textarea name=\"deff\" id=\"deff\" cols=\"45\" rows=\"2\">"; echo $row['deff']; print "</textarea></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><input type=\"submit\" value=\"Save\" />
        <input type=\"reset\" value=\"Cancel\" /></td>
      </tr>
    </table>
    ";
    }
    }
    ?>
</form>
</body>
</html>



dbupdate.php
<?php
session_start();

$equ = $_POST['equ'];
$deff = $_POST['deff'];

include 'config.php';
$id=$_SESSION['id'];
if($id==-1)
{
mysql_query("INSERT INTO `jobs`.`job`( equ, deff) VALUES ( '$equ','$deff')");
$job_id = mysql_insert_id();
}
else{
mysql_query("UPDATE `jobs`.`job` SET equ='$equ',deff='$deff' WHERE id=$id");   
}
echo "ok";
?>


enter.php
<?php
echo $_GET['id'];
?>
<html>
<head>
<title>Update</title>
</head>
<body>
<a href="category.php">category>></a><a href="enter.php">update>></a>
<?php
$connect = mysql_connect("localhost", "root", "") or
die ("check your server connection.");
mysql_select_db("jobs");
$quey1="select * from job ORDER BY id";
$result=mysql_query($quey1) or die(mysql_error());
?>
<table border=1 style="background-color:#FFFF;" >
<tr>   
    <th>Equipment</th>
    <th>Deffect</th>
    <th>Edit</th>
    <th>Delete</th>
</tr>
<?php
    while($row=mysql_fetch_array($result)){
        //print_r($row);
?>
<tr>   
    <td><?php echo $row['equ']; ?></td>
    <td><?php echo $row['deff']; ?></td>
    <td><a href="update.php?id=<?php echo $row['id']; echo $row['edit']; ?>">Edit</a></td>       
    <td><a href="edit.php?id=<?php echo $row['id']; echo $row['delete']; ?>">Delete</a></td>       
</tr>
<?php
    }
?>
</table>
</body>
</html>




edit.php

<html>
<head>
<title>Delete a Record from MySQL Database</title>
</head>
<body>
<?php
include 'config.php';
$id = $_GET['id'];
mysql_select_db('jobs');
mysql_query("DELETE `jobs`.`job` SET equ='$equ',deff='$deff' WHERE id=$id");

$retval = mysql_query( $sql, $link );
if(! $retval )
{
  die('Could not delete data: ' . mysql_error());
}
echo "Deleted data successfully";
mysql_close($link);

?>
</body>
</html>

No comments:

Post a Comment