Skip to main content

PART 2 : Php Add Edit Delete Update Example for freshers

By May 4, 2012Jquery, PHP
1. Use Part 1 instruction for table and database
2. Create  register.php


$con = mysql_connect(“localhost”,”root”,””);

if (!$con){
  die(‘Could not connect: ‘ . mysql_error());

mysql_select_db(“sampletest”, $con);

if($_GET[‘type’] == ‘delete’){
    $delquery = “delete from user where id='” . $_GET[‘id’] . “‘”;

}else if($_GET[‘type’] == ‘update’){

    $selquery = “select * from user where id='” . $_GET[‘id’] . “‘”;
    $rsquery = mysql_query($selquery);
    $arrquery = mysql_fetch_array($rsquery);


if($_POST[‘submitbutton’] == ‘Add’){

    $name= $_POST[‘name’];
    $email= $_POST[’email’];
    $phone= $_POST[‘phone’];
    $query= $_POST[‘query’];

    $query = “insert into user (name, email, phone, query) values (‘”.$name.”‘,'”.$email.”‘ ,'”.$phone.”‘ ,'”.$query.”‘)”;

if($_POST[‘submitbutton’] == ‘Update’){
    $id = $_POST[‘hidd’];
    $name= $_POST[‘name’];
    $email= $_POST[’email’];
    $phone= $_POST[‘phone’];
    $query= $_POST[‘query’];

    $query = “update user set name = ‘”.$name.”‘, email = ‘”.$email.”‘, phone='”.$phone.”‘, query='”.$query.”‘ where id='”.$id.”‘”;

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “”>
  <title> New Document </title>
  <meta name=”Generator” content=”EditPlus”>
  <meta name=”Author” content=””>
  <meta name=”Keywords” content=””>
  <meta name=”Description” content=””>

  <script type=”text/javascript” src=””></script>
  <script type=”text/javascript” src=””></script>

  <script type=”text/javascript”>

$(document).ready(function() {  


        rules: {
            name: “required”,
            email: “required”,          
            query: “required”,       

            name: {
                required: true

            phone: {
                required: true
            email: {
                required: true,
                email: true


        messages: {          

            name: {
                required: “Please enter Name”
            email: “Please enter a valid email address”,
            query: “Please enter a valid query”          





<style type=”text/css”>
    .error {
        color: red;       
        font-style: italic;
        margin-left: 10px;
        width: auto !important;
        float: left;
        width: 100px;
        font-weight: bold;
    input[type=text], textarea{
        width: 270px;
        border:1px solid #d8d5d0;
        -webkit-border-radius: 7px;-moz-border-radius: 7px;border-radius: 7px;

    textarea {
        height: 150px;

        -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px;
        padding:3px 10px;


    <form name=”frm” id=”frm” action=”” method=”POST”>
        <input type=”hidden” id=”hidd” name=”hidd” value=”<?php echo $arrquery[‘id’]; ?>”>
        <span id=”lab”>Name</span>
        <input type=”text” name=”name” id=”name” value=”<?php echo $arrquery[‘name’]; ?>”><br>
        <span id=”lab”>Email</span>
        <input type=”text” name=”email” id=”email” value=”<?php echo $arrquery[’email’]; ?>”><br>
        <span id=”lab”>Phone</span>
        <input type=”text” name=”phone” id=”phone” value=”<?php echo $arrquery[‘phone’]; ?>”><br>
        <span id=”lab”>Query</span>
        <textarea id=”query” name=”query”><?php echo $arrquery[‘query’]; ?></textarea>

        <?php if($_GET[‘type’] == ‘update’) { ?>
        <input type=”submit” name=”submitbutton” id=”submitbutton” value=”Update” class=”submitbutton”/>
        <input type=”submit” name=”submitbutton” id=”submitbutton” value=”Add” class=”submitbutton”/>
        <?php } else {?>
        <input type=”submit” name=”submitbutton” id=”submitbutton” value=”Add” class=”submitbutton”/>
        <?php } ?>
    <table width=”100%” cellpadding=”0″ cellspacing=”0″ border=”0″>

        $select = “select * from user”;

        $rsSelect = mysql_query($select);

        while($arrSelect = mysql_fetch_array($rsSelect)){
            <td><?php echo $arrSelect[‘name’]; ?></td>
            <td><?php echo $arrSelect[‘Email’]; ?></td>
            <td><?php echo $arrSelect[‘Phone’]; ?></td>
            <td><a href=’http://localhost/sampletest/register.php?type=update&id=<?php echo $arrSelect[‘id’]; ?>’>Update</a> / <a href=’http://localhost/sampletest/register.php?type=delete&id=<?php echo $arrSelect[‘id’]; ?>’>Delete</a></td>   
    <?php } ?>


Leave a Reply

− 7 = 3

Open chat
💬 Need help?
Hello 👋
We are expert at building website and digital properties. Do you have an idea that you want to bring to life. Let us know and we will build it for you.