Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2005
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    re-populating an SQL database via user input from a contenteditable cell or a <select

    I am a bit new to the world of SQL/HTML/PHP/Javascript, and trying to utilize all 4 together has had quite a steep learning curve! I've built a tool which reads a bunch of data from a database and outputs it onto the screen. Some of the columns are just for people to read, while other columns allow people to input data using things like:

    Code:
    echo "<td style='width:70' contenteditable='true'> " . $row['Comments'] . " </td>";
    or
    Code:
    echo "<td>" . $row['Recommendations'] . "
    <select>
    <option value='null'></option>
    
    <option value='No Action Taken'>No Action Taken</option>
    <option value='Escalation'>Escalation</option>
    </select>
    </td>";
    I am finding it very difficult, even after reading through other forum posts, to find a way to take the data that is input either into a contenteditable cell or a <select> and, upon entry, entering that data BACK into my database via an UPDATE command. I don't know how to write this, or how to make the trigger work.

    Is anyone able to help explain to me how to get this to work?

    I am using a mixture of HTML, PHP, Jquery, (installed but I have no idea how to use it,) and SQL.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,554
    Thanks
    80
    Thanked 4,620 Times in 4,583 Posts
    You can NOT use a content editable cell. Well, you can, but it's really complex.

    You should use
    Code:
    echo "<td style='width:70' ><input name="comments" value ='" . $row['Comments'] . "'/></td>";
    And your <select> needs a name as well:
    Code:
    <select name="recommendations">
    ONLY <form> fields with NAMES are submitted back to PHP! This is a REQUIREMENT of the browser, per the HTML specification.

    If you have multiple rows with the same form names, then there are two ways to handle this in PHP.
    (1) put [] on the end of every name. e.g., "recommendations[]"
    But this doesn't work for radio buttons or checkboxes if the user doesn't select any of them. NO DATA at all is then sent to PHP.
    (2) So I think the better solution is to number the fields
    "recommndations1", "recommndations2", "recommndations3", ...

    Then your PHP code simply processes one row at a time via
    PHP Code:
    for ( $n 1$n <= 10; ++$n /* replace 10 with appropriate number */
    {
        
    $recoommendation $_POST["recommendation" $n];
        
    $comments $_POST["comments" $n];
        ... 
    etc. ...

    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    lordterrin (09-04-2014)

  • #3
    New Coder
    Join Date
    Nov 2005
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts
    First off, thanks a lot for getting back to me. I really appreciate it. We'll handle my syntax issues first I guess

    What you say makes sense, and I was thinking I may have to do something like your $n example. Since my ultimate goal is to write this back into an UPDATE statement in SQL, would it make sense for me to tie the value of $n back to the ID of the specific item's row in question, that way I can write the UPDATE to include WHERE lineID = ...?

    So I've changed the first bit to read
    Code:
    echo "<td style='width:50'><input name='PMC' value='" . $row['PMComments'] . "'/></td>";
    And I've given the second bit a name.
    Code:
    <?php
    while($row = mysqli_fetch_array($result)) {
    
    echo "<tr>"; ...echo "<other tds....>...."; echo "<td style='width:50'><input name='PMC' value='" . $row['PMComments'] . "'/></td>"; echo "<td>" . $row['Recommendations'] . "
    <select name='PMR'> <option value='null'></option> <option value='No Action Taken'>No Action Taken</option> <option value='Escalation'>Escalation</option> </select>
    </td>"; echo "</table>";
    mysqli_close($con); ?>
    I'm confused however as to where this PHP code that you mention above goes.

  • #4
    New Coder
    Join Date
    Nov 2005
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts
    bump?


  •  

    Posting Permissions

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