admin管理员组

文章数量:1122846

I am trying to edit the data from the table in the frontend. when I click the edit the form doesn't anything it show only empty field

Html Code

<form action="" id="postjob" method="post">
    <table>
        <tr>
            <td><label for="team_uniqueid">UniqueID:</label></td>
            <td><input type="text" name="team_uniqueid" id="team_uniqueid" value=""/></td>
        </tr>
        <tr>
            <td><label for="team_firstname">FirstName:</label></td>
            <td><input type="text" name="team_firstname" id="team_firstname" value="" /></td>
        </tr>
        <tr>
            <td><label for="team_lastname">LastName:</label></td>
            <td><input type="text" name="team_lastname" id="team_lastname" /></td>
        </tr>
        <tr>
            <td><label for="team_emailid">EmailId:</label></td>
            <td><input type="text" name="team_emailid" id="team_emailid" /></td>
        </tr>
        <tr>
      
        <div class="full_wrap">
                <div class="sub_wrap">
                    <select name="page_id" id="page_id">
                    <?php
                    global $post;
                    $args = array( 'numberposts' => -1);
                    $posts = get_posts($args);
                    foreach( $posts as $post ) : setup_postdata($post); ?>
                        <option value="<?php echo $post->ID; ?>"><?php the_title(); ?></option>
                    <?php endforeach; ?>
                    </select>
                    <select>
                        <option class="au">Australia</option>
                        <option class="Ind">India</option>
                        <option class="US">United States</option>
                        <option class="UK">United Kingdom</option>
                    
                    </select>

                </div>
        </div>                              
        
        </tr>
        
     
        <tr>
            <td><button type="submit" name="insert_member">Submit</button></td>
        </tr>
    </table>
</form>

Edit Code

if (isset($_GET['edit'])) {
    $id = $_GET['edit'];
    $update = true;
    $record = $wpdb->get_results("SELECT * FROM $tablename WHERE team_emailid = '".$id."'");
    

    if($record->num_rows){
        $n = $record->fetch_array();
        $team_uniqueid = $n['team_uniqueid'];
        $team_firstname = $n['team_firstname'];
        $team_lastname = $n['team_lastname'];
        $team_emailid1 = $n['team_emailid'];

    }
}

I am trying to edit the data from the table in the frontend. when I click the edit the form doesn't anything it show only empty field

Html Code

<form action="" id="postjob" method="post">
    <table>
        <tr>
            <td><label for="team_uniqueid">UniqueID:</label></td>
            <td><input type="text" name="team_uniqueid" id="team_uniqueid" value=""/></td>
        </tr>
        <tr>
            <td><label for="team_firstname">FirstName:</label></td>
            <td><input type="text" name="team_firstname" id="team_firstname" value="" /></td>
        </tr>
        <tr>
            <td><label for="team_lastname">LastName:</label></td>
            <td><input type="text" name="team_lastname" id="team_lastname" /></td>
        </tr>
        <tr>
            <td><label for="team_emailid">EmailId:</label></td>
            <td><input type="text" name="team_emailid" id="team_emailid" /></td>
        </tr>
        <tr>
      
        <div class="full_wrap">
                <div class="sub_wrap">
                    <select name="page_id" id="page_id">
                    <?php
                    global $post;
                    $args = array( 'numberposts' => -1);
                    $posts = get_posts($args);
                    foreach( $posts as $post ) : setup_postdata($post); ?>
                        <option value="<?php echo $post->ID; ?>"><?php the_title(); ?></option>
                    <?php endforeach; ?>
                    </select>
                    <select>
                        <option class="au">Australia</option>
                        <option class="Ind">India</option>
                        <option class="US">United States</option>
                        <option class="UK">United Kingdom</option>
                    
                    </select>

                </div>
        </div>                              
        
        </tr>
        
     
        <tr>
            <td><button type="submit" name="insert_member">Submit</button></td>
        </tr>
    </table>
</form>

Edit Code

if (isset($_GET['edit'])) {
    $id = $_GET['edit'];
    $update = true;
    $record = $wpdb->get_results("SELECT * FROM $tablename WHERE team_emailid = '".$id."'");
    

    if($record->num_rows){
        $n = $record->fetch_array();
        $team_uniqueid = $n['team_uniqueid'];
        $team_firstname = $n['team_firstname'];
        $team_lastname = $n['team_lastname'];
        $team_emailid1 = $n['team_emailid'];

    }
}
Share Improve this question asked Oct 14, 2020 at 19:44 SnowSnow 1 4
  • When you use SELECT * you're running a query to get ALL so by default it returns an array of results, even if it only finds one. So you may need to specify which offset in the array you're looking for. – Tony Djukic Commented Oct 14, 2020 at 20:40
  • 1 @TonyDjukic as you mentioned it return as array so I have changes this line $result = $wpdb->get_row("SELECT team_uniqueid,team_firstname,team_lastname,team_emailid FROM $tablename WHERE team_emailid = '".$id."'"); It start working – Snow Commented Oct 15, 2020 at 13:55
  • @TonyDjukic it is working now – Snow Commented Oct 15, 2020 at 13:57
  • Great news. You should post your findings as an answer and accept it so that the next person who encounters this can use your answer to solve their problem. :-) Well done. – Tony Djukic Commented Oct 15, 2020 at 13:57
Add a comment  | 

1 Answer 1

Reset to default 0

Good day! To edit the existing field, you need to put the values inside your input fields. You can do that in this way-

<tr>
     <td><label for="team_uniqueid">UniqueID:</label></td>
     <td><input type="text" name="team_uniqueid" id="team_uniqueid" value="<?php echo $team_uniqueid; ?>"/></td>
</tr>

I hope, this will help.

本文标签: databaseHow to edit custom table data in frontend