تمرین به روز رسانی

پرسیده شده
فعالیت 1464 روز پیش
دیده شده 952 بار
0
function wp_apis_main_menu_handler(){

    global $wpdb;
    $action = $_GET['action'];
    if ($action == "delete"){
    
        $item= intval($_GET['item']);
        if($item > 0){
            $wpdb -> delete($wpdb->prefix .'sample', ['ID' => $item]);
        }
    }
    if ($action == "add"){
        if(isset($_POST['saveData'])){
        
            $wpdb->insert($wpdb->prefix .'sample', 
            ['firstName'=> $_POST['firstName'],'lastName' => $_POST['lastName'],
                'mobile' => $_POST['mobile']
            ]);
            
        }
        include WP_APIS_TPL.'admin/menus/add.php';
        return; 
    }     
    if ($action == "update"){
        $item= intval($_GET['item']);
        if( $item > 0 && isset($_POST['updateData'])){
            $wpdb->update($wpdb->prefix .'sample', ['firstName'=> $_POST['firstName'],'lastName' => $_POST['lastName'],
                'mobile' => $_POST['mobile']
            ] ,['ID' => $item]);         
        }
        
        $update_date= $wpdb-> get_results("SELECT * FROM {$wpdb->prefix}sample  WHERE ID = $item");
       
        include WP_APIS_TPL.'admin/menus/update.php';          
    }
        if($action !=="add"&& $action !="update"){
            $samples = $wpdb-> get_results("SELECT * FROM {$wpdb->prefix}sample");
    
        include WP_APIS_TPL.'admin/menus/main.php';  
        
    }
} 
?>
 قسمت فرم نمایشی

<div class="warp">
<h1>بروزرسانی اطلاعات</h1>


<form  method="post">
 <table class="form-table">
   <tr valign = "top">
        <th scope="row">نام</th>
        <td>
            <input type="text" name="firstName" value="<?PHP echo $firstName; ?>" />
        </td>
    </tr>

    <tr valign = "top">
        <th scope="row">نام خانوادگی</th>
        <td>
            <input type="text" name="lastName" value="<?PHP echo $lastName; ?>" />
        </td>
    </tr>

    <tr valign = "top">
        <th scope="row">شماره همراه</th>
        <td>
            <input type="text" name="mobile" value="<?PHP echo $mobile; ?>" />
        </td>
    </tr>

    <tr valign = "top">
        <th scope="row"></th>
        <td>
            <input type="submit" class="button" name="saveData" value="ذخیره سازی"/>
        </td>
    </tr>

  </table>
 </form>
</div>

 

فایل پیوست

ایران
ایران

10 اردیبهشت 99