Simple jQuery Add, Update, Delete with PHP and MySQL | Coding Cage

Simple jQuery Add, Update, Delete with PHP and MySQL

By
In this tutorial we will cover a simple Insert, Update and Delete using jQuery, PHP and MySQL with PDO, well we have lot's of CRUD tutorials on this blog but we haven't jQuery CRUD tutorial yet, and few email requests i received from readers regarding jQuery Insert, Update, Delete with PHP MySQL, so here in this tutorial we will do it, using jQuery to perform such operations become easy and for the better user interface bootstrap is here i have used, let's start.
Simple jQuery Insert, Update, Delete with PHP & MySQL


Database & Table

i have created employees table here in "jquery_crud" database, just create "jquery_crud" database in your PHPMyAdmin and paste following SQL code it will create the table.

CREATE TABLE IF NOT EXISTS `tbl_employees` (
  `emp_id` int(11) NOT NULL AUTO_INCREMENT,
  `emp_name` varchar(25) NOT NULL,
  `emp_dept` varchar(50) NOT NULL,
  `emp_salary` varchar(7) NOT NULL,
  PRIMARY KEY (`emp_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

dbconfig.php

as usual simple database configuration file with PDO extension.
<?php

 $db_host = "localhost";
 $db_name = "jquery_crud";
 $db_user = "root";
 $db_pass = "";
 
 try{
  
  $db_con = new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_pass);
  $db_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 }
 catch(PDOException $e){
  echo $e->getMessage();
 }

?>

index.php

i know it looks little lengthy but to use bootstrap design and jquery functions we have to add, contains code which displays MySQL employee records from the table, little jQuery i have used here it will used to load insert, update form directly without page refresh, MySQL records will be displayed within jQuery Datatable.

<!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=utf-8" />
<title>Insert, Update, Delete using jQuery, PHP and MySQL</title>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" media="screen"> 
<link href="assets/datatables.min.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="assets/jquery-1.11.3-jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){
 
 $("#btn-view").hide();
 
 $("#btn-add").click(function(){
  $(".content-loader").fadeOut('slow', function()
  {
   $(".content-loader").fadeIn('slow');
   $(".content-loader").load('add_form.php');
   $("#btn-add").hide();
   $("#btn-view").show();
  });
 });
 
 $("#btn-view").click(function(){
  
  $("body").fadeOut('slow', function()
  {
   $("body").load('index.php');
   $("body").fadeIn('slow');
   window.location.href="index.php";
  });
 });
 
});
</script>

</head>

<body>
    

 <div class="container">
      
        <h2 class="form-signin-heading">Employee Records.</h2><hr />
        <button class="btn btn-info" type="button" id="btn-add"> <span class="glyphicon glyphicon-pencil"></span> &nbsp; Add Employee</button>
        <button class="btn btn-info" type="button" id="btn-view"> <span class="glyphicon glyphicon-eye-open"></span> &nbsp; View Employee</button>
        <hr />
        
        <div class="content-loader">
        
        <table cellspacing="0" width="100%" id="example" class="table table-striped table-hover table-responsive">
        <thead>
        <tr>
        <th>Emp ID</th>
        <th>Emp Name</th>
        <th>department</th>
        <th>salary</th>
        <th>edit</th>
        <th>delete</th>
        </tr>
        </thead>
        <tbody>
        <?php
        require_once 'dbconfig.php';
        
        $stmt = $db_con->prepare("SELECT * FROM tbl_employees ORDER BY emp_id DESC");
        $stmt->execute();
  while($row=$stmt->fetch(PDO::FETCH_ASSOC))
  {
   ?>
   <tr>
   <td><?php echo $row['emp_id']; ?></td>
   <td><?php echo $row['emp_name']; ?></td>
   <td><?php echo $row['emp_dept']; ?></td>
   <td><?php echo $row['emp_salary']; ?></td>
   <td align="center">
   <a id="<?php echo $row['emp_id']; ?>" class="edit-link" href="#" title="Edit">
   <img src="edit.png" width="20px" />
            </a></td>
   <td align="center"><a id="<?php echo $row['emp_id']; ?>" class="delete-link" href="#" title="Delete">
   <img src="delete.png" width="20px" />
            </a></td>
   </tr>
   <?php
  }
  ?>
        </tbody>
        </table>
        
        </div>

    </div>
    
<script src="bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="assets/datatables.min.js"></script>
<script type="text/javascript" src="crud.js"></script>

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
 $('#example').DataTable();

 $('#example')
 .removeClass( 'display' )
 .addClass('table table-bordered');
});
</script>
</body>
</html>

add_form.php

simple html form to insert employee records contains three text box to enter employee name, department and salary, it will be loaded within "index.php" by clicking "add employee" button.

<style type="text/css">
#display{
 display:none;
}
</style>
    
    <div id="display">
    <!-- here message will be displayed -->
 </div>
        
  
  <form method='post' id='emp-SaveForm' action="#">
 
    <table class='table table-bordered'>
 
        <tr>
            <td>Employee Name</td>
            <td><input type='text' name='emp_name' class='form-control' placeholder='EX : john doe' required /></td>
        </tr>
 
        <tr>
            <td>Employee Department</td>
            <td><input type='text' name='emp_dept' class='form-control' placeholder='EX : Web Design, App Design' required></td>
        </tr>
 
        <tr>
            <td>Employee Salary</td>
            <td><input type='text' name='emp_salary' class='form-control' placeholder='EX : 180000' required></td>
        </tr>
 
        <tr>
            <td colspan="2">
            <button type="submit" class="btn btn-primary" name="btn-save" id="btn-save">
      <span class="glyphicon glyphicon-plus"></span> Save this Record
   </button>  
            </td>
        </tr>
 
    </table>
</form>

create.php

this will insert a new record using jQuery into tbl_employees, on submit button click #emp-SaveForm form will be submitted using jQuery.

<?php
require_once 'dbconfig.php';
 
 if($_POST)
 {
  $emp_name = $_POST['emp_name'];
  $emp_dept = $_POST['emp_dept'];
  $emp_salary = $_POST['emp_salary'];
  
  try{
   
   $stmt = $db_con->prepare("INSERT INTO tbl_employees(emp_name,emp_dept,emp_salary) VALUES(:ename, :edept, :esalary)");
   $stmt->bindParam(":ename", $emp_name);
   $stmt->bindParam(":edept", $emp_dept);
   $stmt->bindParam(":esalary", $emp_salary);
   
   if($stmt->execute())
   {
    echo "Successfully Added";
   }
   else{
    echo "Query Problem";
   } 
  }
  catch(PDOException $e){
   echo $e->getMessage();
  }
 }
?>

edit_form.php

to fetch editable data from index.php and the data will be set within the following text box to update, this will loaded too within index.php file in #container div, this jquery code will set QueryString to edit_form.php : $(".content-loader").load('edit_form.php?edit_id='+edit_id);

<?php
include_once 'dbconfig.php';

if($_GET['edit_id'])
{
 $id = $_GET['edit_id']; 
 $stmt=$db_con->prepare("SELECT * FROM tbl_employees WHERE emp_id=:id");
 $stmt->execute(array(':id'=>$id)); 
 $row=$stmt->fetch(PDO::FETCH_ASSOC);
}

?>
<style type="text/css">
#dis{
 display:none;
}
</style>
    
    <div id="dis">
    
 </div>
         
  <form method='post' id='emp-UpdateForm' action='#'>
 
    <table class='table table-bordered'>
   <input type='hidden' name='id' value='<?php echo $row['emp_id']; ?>' />
        <tr>
            <td>Employee Name</td>
            <td><input type='text' name='emp_name' class='form-control' value='<?php echo $row['emp_name']; ?>' required></td>
        </tr>
 
        <tr>
            <td>Employee Department</td>
            <td><input type='text' name='emp_dept' class='form-control' value='<?php echo $row['emp_dept']; ?>' required></td>
        </tr>
 
        <tr>
            <td>Employee Salary</td>
            <td><input type='text' name='emp_salary' class='form-control' value='<?php echo $row['emp_salary']; ?>' required></td>
        </tr>
 
        <tr>
            <td colspan="2">
            <button type="submit" class="btn btn-primary" name="btn-update" id="btn-update">
      <span class="glyphicon glyphicon-plus"></span> Save Updates
   </button>
            </td>
        </tr>
 
    </table>
</form>

update.php

simple file which will update the selected row from the "edit_form.php" and this will be loaded too via a jQuery on submit function.

<?php
require_once 'dbconfig.php';
 
 if($_POST)
 {
  $id = $_POST['id'];
  $emp_name = $_POST['emp_name'];
  $emp_dept = $_POST['emp_dept'];
  $emp_salary = $_POST['emp_salary'];
  
  $stmt = $db_con->prepare("UPDATE tbl_employees SET emp_name=:en, emp_dept=:ed, emp_salary=:es WHERE emp_id=:id");
  $stmt->bindParam(":en", $emp_name);
  $stmt->bindParam(":ed", $emp_dept);
  $stmt->bindParam(":es", $emp_salary);
  $stmt->bindParam(":id", $id);
  
  if($stmt->execute())
  {
   echo "Successfully updated";
  }
  else{
   echo "Query Problem";
  }
 }
?>

delete.php

this file will delete rows from mysql - a simple code loaded via jQuery and delete rows from mysql without page refresh. id will be get through this function : $.post('delete.php', {'del_id':del_id}

<?php
include_once 'dbconfig.php';

if($_POST['del_id'])
{
 $id = $_POST['del_id']; 
 $stmt=$db_con->prepare("DELETE FROM tbl_employees WHERE emp_id=:id");
 $stmt->execute(array(':id'=>$id)); 
}
?>

crud.js

finally here is the complete jQuery file which will responsible to perform Insert, Update and Delete contains only jQuery/JavaScript code.

// JavaScript Document

$(document).ready(function(){
 
 /* Data Insert Starts Here */
 $(document).on('submit', '#emp-SaveForm', function() {
   
    $.post("create.php", $(this).serialize())
        .done(function(data){
   $("#dis").fadeOut();
   $("#dis").fadeIn('slow', function(){
     $("#dis").html('<div class="alert alert-info">'+data+'</div>');
        $("#emp-SaveForm")[0].reset();
       }); 
   });   
      return false;
    });
 /* Data Insert Ends Here */
 
 
 /* Data Delete Starts Here */
 $(".delete-link").click(function()
 {
  var id = $(this).attr("id");
  var del_id = id;
  var parent = $(this).parent("td").parent("tr");
  if(confirm('Sure to Delete ID no = ' +del_id))
  {
   $.post('delete.php', {'del_id':del_id}, function(data)
   {
    parent.fadeOut('slow');
   }); 
  }
  return false;
 });
 /* Data Delete Ends Here */
 
 /* Get Edit ID  */
 $(".edit-link").click(function()
 {
  var id = $(this).attr("id");
  var edit_id = id;
  if(confirm('Sure to Edit ID no = ' +edit_id))
  {
   $(".content-loader").fadeOut('slow', function()
    {
    $(".content-loader").fadeIn('slow');
    $(".content-loader").load('edit_form.php?edit_id='+edit_id);
    $("#btn-add").hide();
    $("#btn-view").show();
   });
  }
  return false;
 });
 /* Get Edit ID  */
 
 /* Update Record  */
 $(document).on('submit', '#emp-UpdateForm', function() {
  
    $.post("update.php", $(this).serialize())
        .done(function(data){
   $("#dis").fadeOut();
   $("#dis").fadeIn('slow', function(){
        $("#dis").html('<div class="alert alert-info">'+data+'</div>');
        $("#emp-UpdateForm")[0].reset();
     $("body").fadeOut('slow', function()
     {
     $("body").fadeOut('slow');
     window.location.href="index.php";
     });     
       }); 
  });   
     return false;
    });
 /* Update Record  */
});

if you have any query regarding this tutorial fill free to contact me, download this jQuery Add, Update, Delete tutorial and try it, that's it isn't it simple :)



52 comments:

  1. Thanks for this wonderful tutorial, can i modify this to include the job cadre? Also, can one use jquery CRUD method to design billing system? thanks again and again

    ReplyDelete
    Replies
    1. Hello Ayobami, thanks for dropping comment, and yes, of cource you can use jQuery Ajax for your billing system.

      Delete
  2. Its not downloading.please helo me

    ReplyDelete
  3. Thanks for you blog, it has really helped me in learning fast. I followed this tutorial. i tweak it a little for the inventory project that i am doing but i have this error. Please can you help me? I often have this error message:

    Notice: Undefined index: stock_status in C:\xampp\htdocs\stock\create.php on line 14

    Notice: Undefined index: date_supplied in C:\xampp\htdocs\stock\create.php on line 15
    SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'stock_descr' cannot be null


    I have this table
    CREATE TABLE IF NOT EXISTS `stock` (
    `stock_id` tinyint(5) NOT NULL AUTO_INCREMENT,
    `stock_name` varchar(20) NOT NULL,
    `stock_categ` varchar(20) NOT NULL,
    `stock_descr` varchar(50) NOT NULL,
    `stock_comp` varchar(20) NOT NULL,
    `stock_supp` varchar(20) NOT NULL,
    `stock_quan` int(11) NOT NULL,
    `cost` int(11) NOT NULL,
    `stock_status` enum('Available','Inavailable') NOT NULL,
    `date_supplied` date NOT NULL,
    PRIMARY KEY (`stock_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;

    The create.php scrpt is
    prepare("INSERT INTO stock(stock_name,stock_categ,stock_descr,stock_comp,stock_supp,stock_quan,cost,stock_status,date_supplied) VALUES(:sname, :scateg, :sdescr,:scomp, :ssupp, :squan,:scost, :sstatus, :ssupplied)");
    $stmt->bindParam(":sname", $stock_name);
    $stmt->bindParam(":scateg", $stock_categ);
    $stmt->bindParam(":sdescr", $$stock_descr);
    $stmt->bindParam(":scomp", $stock_comp);
    $stmt->bindParam(":ssupp", $stock_supp);
    $stmt->bindParam(":squan", $stock_quan);
    $stmt->bindParam(":scost", $cost);
    $stmt->bindParam(":sstatus", $stock_status);
    $stmt->bindParam(":ssupplied", $date_supplied);

    if($stmt->execute())
    {
    echo "Successfully Added";
    }
    else{
    echo "Query Problem";
    }
    }
    catch(PDOException $e){
    echo $e->getMessage();
    }
    }

    ?>
    The update.php code is
    prepare("UPDATE stock SET stock_name=:sn, stock_categ=:sc, stock_descr=:sd,stock_comp=:sc,stock_supp=:ss,stock_quan=:sq,cost=:c,stock_status=:ss,date_supplied=:ds WHERE emp_id=:id");
    $stmt->bindParam(":sn", $stock_name);
    $stmt->bindParam(":sc", $stock_categ;
    $stmt->bindParam(":sd", $stock_descr);
    $stmt->bindParam(":sc", $stock_comp);
    $stmt->bindParam(":ss", $stock_supp);
    $stmt->bindParam(":sq", $stock_quan);
    $stmt->bindParam(":c", $cost);
    $stmt->bindParam(":ss", $stock_status;
    $stmt->bindParam(":ds", $date_supplied);
    $stmt->bindParam(":id", $id);

    if($stmt->execute())
    {
    echo "Successfully updated";
    }
    else{
    echo "Query Problem";
    }
    }

    ?>
    Your reply will be highly valued and appreciated. Thanks in advance.

    ReplyDelete
    Replies
    1. Did you ever find a solution? same problem here.
      thanks

      Delete
  4. Hi, I'm a totally beginner to php and really thank you for these wonderful tutorials, i learn a lot from here! I've tried combining this tutorial along with registration and login tutorial you posted previously and i'm able to develop a system with registration, login and updating profile. It's working perfectly in terms of functionality, however, it can be easily be hacked. For example, the data of user A can be changed by userB, is there anyway i can strengthen the security?

    ReplyDelete
  5. Hi, I'm a totally beginner to php and really thank you for these wonderful tutorials, i learn a lot from here! I've tried combining this tutorial along with registration and login tutorial you posted previously and i'm able to develop a system with registration, login and updating profile. It's working perfectly in terms of functionality, however, it can be easily be hacked. For example, the data of user A can be changed by userB, is there anyway i can strengthen the security?

    ReplyDelete
  6. Hi, first of all, really thank you for all these wonderful tutorials. I'm a total beginner in php and i learn a lot from here! I've tried modify and combine this tutorial with registration and login tutorials you shared previously and it works! However, while it works perfectly in terms of functionality, it seems kinda vulnerable to hack, for example, data of userA can be easily altered by userB, is there any way to strengthen the security?

    ReplyDelete
  7. Good day, may i know what is the function of this following line?

    $(".content-loader").load('edit_form.php?edit_id='+edit_id);

    especially the content in .load(), dont quite understand there. Would really appreciate if you can clarify to me :)

    ReplyDelete
  8. Great Tutorial! but i notice there's only client side validation, none on the server side, or did I mislooked something?

    ReplyDelete
  9. Delete code is not working :(

    ReplyDelete
  10. I want something like this, I am just learning php, want to create admin panel that can insert,update, delete employee profile. Where every employer has a unique user name and password that opens up their profile containing their name, passport, position, address, country etc. I have been studying to see how i can create it then I saw your miracle website. Can you show me how to go from here? thanks

    ReplyDelete
  11. Thanks for this excellent tutorial; Just a question, how or where do you put the searh box on the code, sorry for my ignorant.

    ReplyDelete
  12. Hello pradeep, im a "mongkey" in scripting, any way, how can i use this combine with logon script which i got from here, thanks in advance

    ReplyDelete
    Replies
    1. Hello Yudabego,
      just put this script after login session or define session in crud (index page)pages so without login it can't access.

      Delete
  13. Thanks for a great tutorial. I have just one issue left before I go live with it. I have a problem with the update function. When I get to the edit page I have the correct record. I can change the entries but when I click the Save Updates button nothing happens, no success of failure. I do not know what I have done wrong. Can you look at my update.php and tell me what is wrong?
    if($_POST)
    {
    $id = $_POST['id'];
    $dealer_name = $_POST['dealer_name'];
    $pi_name = $_POST['pi_name'];
    $pi_id = $_POST['pi_id'];
    $pi_key = $_POST['pi_key'];
    $sip_server = $_POST['sip_server'];
    $sip_user = $_POST['sip_user'];
    $sip_pass = $_POST['sip_pass'];
    $digits = $_POST['digits'];
    $schedule = $_POST['schedule'];
    $next = $_POST['next'];
    $interval = $_POST['interval'];


    $stmt = $db_con->prepare("UPDATE pi_config SET dealer_name=:en, pi_name=:ed, pi_id=:es , pi_key=:pk, sip_server=:ss, sip_user=:su, sip_pass=:sp, digits=:di, schedule=:sc, next=:ne, interval=:in WHERE id=:id");
    $stmt->bindParam(":en", $dealer_name);
    $stmt->bindParam(":ed", $pi_name);
    $stmt->bindParam(":es", $pi_id);
    $stmt->bindParam(":pk", $pi_key);
    $stmt->bindParam(":ss", $sip_server);
    $stmt->bindParam(":su", $sip_user);
    $stmt->bindParam(":sp", $sip_pass);
    $stmt->bindParam(":di", $digits);
    $stmt->bindParam(":sc", $schedule);
    $stmt->bindParam(":ne", $next);
    $stmt->bindParam(":in", $interval);
    $stmt->bindParam(":id", $id);

    if($stmt->execute())
    {
    echo "Successfully updated";
    }
    else{
    echo "Query Problem";
    }
    }


    Thank you so much!!

    ReplyDelete
  14. Any reason why this wouldn't work in Chrome? I can't click on the Edit or Delete.

    ReplyDelete
    Replies
    1. My friend told, firefox is the best browser to test any code..
      I dont know..

      Delete
  15. Hi, I want to know if something like this can work with Phonegap.
    My idea is to put the PHP at a web server and work with JS at the client side.
    Sorry about my bad english.

    ReplyDelete
  16. Hello bro,
    could you make tutorial how to display data from more table and edit them in one page??
    thanks..

    ReplyDelete
  17. Muy buen post, solo falta agregar la opción o las configuraciones de internacionalización bajo el siguiente codigo:

    language: {
    processing: "Procesando...",
    search: "Buscar :",
    lengthMenu: "Paginación _MENU_ elementos",
    info: "Página _START_ de _END_ de _TOTAL_ elementos",
    infoEmpty: "0 Registros",
    infoFiltered: "(filtré de _MAX_ éléments au total)",
    infoPostFix: "",
    loadingRecords: "Cargando...",
    zeroRecords: "No se encontraron registros",
    //emptyTable: "No se Enc",
    paginate: {
    first: "Primero",
    previous: "Anterior",
    next: "Siguiente",
    last: "Último"
    },
    aria: {
    sortAscending: ": activer pour trier la colonne par ordre croissant",
    sortDescending: ": activer pour trier la colonne par ordre décroissant"
    }
    }

    ReplyDelete
  18. Thanks for this wonderful tutorial,how can i prevent duplicate entry and show message "This data already exist".

    ReplyDelete
    Replies
    1. hello there, just select emp_name while inserting using jquery and make a another page to get emp_name then call another page via $.ajax()

      this may help you ..

      http://www.codingcage.com/2015/09/jquery-username-availability-live-check.html

      Delete
    2. Thanks a lot my friend, it works like a charm.

      Delete
  19. thanks for your tutorial....

    ReplyDelete
  20. in localhost working fine. Some problem in live that is unable to add,delete,update in live

    ReplyDelete
  21. If client uses link directly: mydomain.com/delete.php?del_id=123. What will happen?

    ReplyDelete
  22. How to upload image with this code? Can you help me?

    ReplyDelete
  23. How are you Sir thanx for good tutorial. I have created a view more link but its not working.I don't know how to go about it. Thank you sir

    ReplyDelete
  24. Thanks.
    I have a question to ask you.
    MySQL >> Set Collation : utf8_unicode_ci (before latin1_swedish_ci)
    dbconfig.php >> Add mysql_query("SET NAMES UTF8");
    Add Data >> language Thailand but Database Incorrect language (สวà ...)
    Thankyou .help me

    ReplyDelete
  25. hi i am realy wanna thank you so much for this tutorial but i need to insert option value which will be echoed by selecting table how can i perform this in my form please help me

    ReplyDelete
  26. Hi. Thank you for your example.
    My sql:
    $stmt = $db_con->prepare("SELECT _id,
    date_publication,
    chanel_title,
    title,
    link,
    img,
    status
    FROM RSS_DATA
    ORDER BY date_publication DESC;");

    but the data in the table are not sorted by date.

    ReplyDelete
    Replies
    1. Hello Arslan, well i have used here jQuery Datatables so it will sort all the columns as datatables default sorting,

      you can use the following code to sort date column as desc


      $('#example').DataTable( {
      "order": [[ 3, "desc" ]]
      });

      here 3 is your date column

      Delete
  27. how to add more Image column with upload image function, pls help me

    ReplyDelete
  28. Hi Pradeep,
    Please tell me how to add datepicker by bootstrap in above form, I will helpful for us to select date by datepicker.

    Thanks in advance,

    ReplyDelete
  29. Hi..i got some issue pertaining this code. I already email to you..kindly assist. Anyway good titorial. Tq..

    ReplyDelete
  30. Sir thanks for the code it is a good one.
    But i need your help to make it display users registration details with users image upload. it will also display like this one in table format with the users image or passport, edit page and update too.

    Thanks

    ReplyDelete
  31. hi
    i tam try to run but there is a error in index 71 line
    Parse error: parse error, expecting `'('' in /

    ReplyDelete
  32. thank you very much for your tutorial'm very happy, greetings from Equador

    ReplyDelete
  33. Thanks for tutorial. for me update not working.

    prepare("UPDATE tbl_employees SET emp_name=:en, emp_company=:ec, emp_email=:em, emp_phone=:ep WHERE emp_id=:id");

    $stmt->bindParam(":en", $emp_name);
    $stmt->bindParam(":ec", $emp_company);
    $stmt->bindParam(":em", $emp_email);
    $stmt->bindParam(":ep", $emp_phone);
    $stmt->bindParam(":id", $id);

    if($stmt->execute())
    {
    echo "Successfully updated";
    }
    else{
    echo "Query Problem";
    }
    }

    ?>

    any error in this page? could you help me?

    ReplyDelete
  34. Great Best Tutorial and Great Work i have visit lots of websites but this one works for me

    ReplyDelete
  35. Is there a limit on the number of fields that we can add? I have an need for a form that will need about 60 - 70 fields. Will this script handle that many? Thanks

    ReplyDelete
  36. Many thanks for this useful script. It helps me solve very complicated part in my web site.

    ReplyDelete
  37. Hello , I want to send id to Add_form.Php, please help me

    ReplyDelete
  38. Hello, I want to send id to Add_form.php, Pls help me

    ReplyDelete
  39. hii coder.. can we also have its JSP version. thanks

    ReplyDelete
  40. No me funciona el update.php


    prepare("UPDATE rastros
    SET rastro_ct=:rct ,
    rastro_funciona=:rf,
    rastro_tipo=:rt,
    rastro_marca=:rm,
    rastro_feccol=:rfc,
    rastro_fecrep=:rfr
    WHERE rastro_id=:id");

    $stmt->bindParam(":rct",$rastro_ct);
    $stmt->bindParam(":rf",$rastro_funciona);
    $stmt->bindParam(":rt",$rastro_tipo);
    $stmt->bindParam(":rm",$rastro_marca);
    $stmt->bindParam(":rfc",$rastro_feccol);
    $stmt->bindParam(":rfr",$rastro_fecrep);
    $stmt->bindParam(":id",$id);

    if($stmt->execute())
    {
    echo "Actualizado exitosamente";
    }
    else
    {
    echo "Los Datos NO HAN SIDO ACTUALIZADO";
    }
    }

    ?>

    ReplyDelete
  41. The update does not work ... could tell me where the error is

    ReplyDelete

  42. The update does not work ... could tell me where the error is

    ReplyDelete