🎉 سال نو، مهارت نو، مشاوره رایگان نقشه راه برنامه نویسی (آفر ویژه ثبت نام قبل از افزایش قیمت 🔥)
۰ ثانیه
۰ دقیقه
۰ ساعت
۳ Erfan Tayebi
ارسال نشدن دیتا به دیتا بیس و عدم نمایش اطلاعات جدید
رضا حل شده توسط رضا

سلام و عرض ادب کدها رو به شکل زیر در فایل‌ها زدم اما دیتا به دیتابیس ارسال نمیشه و اطلاعات جدید هم نمایش داده نمیشه ممنون میشم بفرمایید مشکل کجاست؟

 

فایل menus:

function wp_apis_users_pages(){
    global $wpdb;
    if(isset($_GET['action']) && $_GET['action']='edit')
    {
        $userID = intval($_GET['id']);
        if(isset($_POST['saveuserinfo'])){
            $mobile=$_POST['mobile'];
            $wallet=$_POST['wallet'];
            if(!empty($mobile)){
                update_user_meta($userID , 'mobile' , $mobile);
            }
            if(!empty($wallet)){
                update_user_meta($userID , 'wallet' , $wallet);
            }
        }
        $mobile = get_user_meta($userID , 'mobile' , true);
        $wallet = get_user_meta($userID , 'wallet' , true);
        include WP_APIS_TPL.'admin/menus/users/edit.php';
        return;
    }
    $users=$wpdb->get_results("SELECT ID,user_email,display_name FROM {$wpdb->users}");
    include WP_APIS_TPL.'admin/menus/users/users.php';
}

 

فایل users:

<div class="wrap">
<h1>کاربران ویژه</h1>
<table class="widefat">
<thead>
<tr>
    <th>شناسه</th>
    <th>نام کامل</th>
    <th>ایمیل</th>
    <th>شماره همراه</th>
    <th>کیف پول</th>
    <th>عملیات</th>
</tr>
</thead>
<tbody>
    <?php foreach($users as $user): ?>
        <tr>
            <td><?php echo $user->ID; ?></td>
            <td><?php echo $user->display_name; ?></td>
            <td><?php echo $user->user_email; ?></td>
            <td><?php echo get_user_meta($user->ID , 'mobile' , true);?></td>
            <td><?php echo number_format(get_user_meta($user->ID , 'wallet' , true)).'تومان'?></td>
            <td>
                <a href="<?php echo add_query_arg(['action' => 'edit' , 'id' => $user->ID]);?>">
                <span class="dashicons dashicons-edit"></span>
            </a>
            </td>
        </tr>
    <?php endforeach ?>
</tbody>
</table>
</div>

فایل edit: 

<div class='wrap'>
<h1>ویرایش اطلاعات کاربران</h1>
<form action="" method="post"></form>
    <table class='form-table'>
    <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="text" name="wallet" value="<?php echo $wallet; ?>" /></td>
    </tr>
    <tr valign="top">
    <th scope="row"></th>
    <td>
        <button class="button" type="submit" name="saveuserinfo">ذخیره سازی اطلاعات</button>
    </tr>
    </table>
</div>

سلام خدمت شما. توی کدها این قطعه کد رو بررسی کنید.

 if(isset($_GET['action']) && $_GET['action']='edit')

برای شرط‌ها باید از == یا === استفاده کنید.

کیوان علی محمدی ۱۴ شهریور ۱۴۰۰، ۰۹:۴۹

سلام و عرض ادب مجدد

برای این شرط از == و === استفاده کردم مشکل حل نشد 

چند بار دستورات دیگه رو هم امتحان کردم اما نشد

ممنون میشم کد رو استفاده بکنید و ببینید برای شما کار میکنه؟ و اینکه مشکل کجاس؟

یا اینکه برای این کار ایا دستور یا تابع جایگزینی وجود داره ؟

Erfan Tayebi ۱۵ شهریور ۱۴۰۰، ۱۶:۰۴

سلام خدمت شما 

کد درست:

  if(isset($_GET['action']) && $_GET['action']='edit')
    {.....}
   if(isset($_POST['saveuserinfo'])){}//فرم

دقت کنید شما هنگام  ارسال فرم  

 $_GET['action']='edit'

)ندارید  

name 

به نام 

edit 

 (ندارید 

<form action="" method="post">
  <table class='form-table'>
    <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="text" name="wallet" value="<?php echo $wallet; ?>" /></td>
    </tr>
    <tr valign="top">
    <th scope="row"></th>
    <td>
        <button class="button" type="submit" name="saveuserinfo">ذخیره سازی اطلاعات</button>
    </tr>
    </table></form>

ولی در 

<?php echo add_query_arg(['action' => 'edit' , 'id' => $user->ID]);?> شما editدارید 

وهمچنین شما فیلدها را داخل فرم قرار ندادید

<form action="" method="post">       شما مابین این دو چیزی قرار ندادید</form>

 

بهترین پاسخ
رضا ۱۶ شهریور ۱۴۰۰، ۰۰:۳۳