SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: Inline Editing

Threaded View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2013
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Inline Editing

    I was trying since two days for this code. I am new to PHP as well.

    My index.php code is
    PHP Code:
    <html>
    <head>
    <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui-1.8.9.custom.min.js"></script>
    <script type="text/javascript" src="js/jquery.qtip-1.0.0.min.js"></script>
    <script type="text/javascript">

    $(document).ready(function(){
      $(".edit").click(function(){
        var tr = $(this).closest("tr");

        tr.find(".td").each(function(){
          var name = $(this).attr("title");
          var value = $(this).html();
          var input = "<input type='text' name='"+name+"' value='"+value+"' />";
          $(this).html(input);
        });

        var submit = "<input type='button' name='Submit' value='Submit' />";
        tr.find(".button").html(submit);

      });
    });

    $(".button input[type=button]").live('click', function() {
      //var data = $('form#change').serialize();
      var data = $('form').serialize();
      // post data using ajax                                                                                                                                                                         
      $.ajax({
        type: "POST",
        url: "index.php?page=update_mysql",
        data: data,
        success: function(data) {
          alert(data); // show response from the php script.                                                                                                                                          
        }
      });
    });
    </script>
    </head>

    <form id="change" method="post" action="#">
        <table>

    <?PHP
    include('db.php');
    $sql="SELECT * FROM liva_projects";
    $result mysql_query($sql)or die(mysql_error());
      WHILE (
    $row mysql_fetch_array($resultMYSQL_ASSOC))  {
            echo 
    '<tr class="row">';
                echo 
    '<td class="td" title="id">'.$row["id"].'</td>';
                echo 
    '<td class="td" title="project_name">'.$row["project_name"].'</td>';
                echo 
    '<td class="td" title="project_tag">'.$row["project_tag"].'</td>';
                echo 
    '<td class="button" title="button"><button class="edit">Edit</button></td>';
            echo 
    '</tr>';
      }
    ?>

        </table>
    </form>
    </html>
    update_mysql.php code is here
    PHP Code:
    <?php
    include('db.php');
    if (
    $_POST['Submit'] == "Submit") {
    $id $_POST['id'];
    $project_name $_POST['project_name'];
    $project_tag $_POST['project_tag'];
    $sql_edit "UPDATE liva_projects SET project_name = '$project_name', project_tag = '$project_tag' WHERE id = '$id'";
    $result_edit mysql_query($sql_edit) or die(mysql_error());

    }

    ?>

    db.php code is here..
    PHP Code:
    <?php
    $mysql_hostname 
    "localhost";
    $mysql_user "root";
    $mysql_password "";
    $mysql_database "livaitne_liva_proman";
    $bd mysql_connect($mysql_hostname$mysql_user$mysql_password) or die("Could not connect database");
    mysql_select_db($mysql_database$bd) or die("Could not select database");
    ?>

    I am not getting editable option when clicking on edit button.

    or else is there any other simple code for inline editing in a table?

    Please help me
    Last edited by cpradio; Oct 2, 2013 at 05:55. Reason: Added php tags


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •