Wordpress自定义表更新无法正常工作

时间:2014-09-29 10:16:23

标签: php jquery mysql wordpress wordpress-theming

我正在尝试通过前端更新wp_table(自定义表)。 我想在自己提交的页面中更新记录$ _SERVER ['PHP_SELF'] 在更新后,我想要将用户重定向到主页。但没有工作

$domain = $_POST['domain'];
$appointment = $_POST['appointment'];
$rid = $_POST['rid'];
global $wpdb;
if (!isset($_POST['save'])) {
    if (mysql_query("UPDATE wp_domain SET domain='$domain', appointmenttime_setting='$appointment' WHERE re_id=$rid"))
    {
    //echo "UPDATE wp_domain SET domain='$domain', cron_setting='$twitime' WHERE re_id=$rid";
    header( 'Location:http://localhost/thepost/?page_id=17' ) ;
    }
}

我的HTML代码在这里

<form method="post" action="<?php $_SERVER['PHP_SELF'] ?>">
    <table width="300" border="1">
  <tr style="width:450px;">
    <td>Domain</td>
    <td>
    <?php
    $act = $Rrow->active_not;
    if($act=="NO")
    { ?>
        <input name="domain" value="<?php echo $Rrow->domain; ?>" type="text">
        <?php
    }
    else
    {
        echo $Rrow->domain;
    }
    ?>

    </td>
  </tr>

  <tr>
    <td>Appointment Time</td>
    <td><select name="appointment">
      <option value="5 Minute">5 Minute</option>
      <option value="10 Minute">10 Minute</option>
      <option value="15 Minute">15  Minute</option>
      <option value="30 Minute">30 Minute</option>
      <option value="45 Minute">45 Minute</option>
      <option value="1 Hour">1 Hour</option>
     </select>
     <input type="hidden" name="rid" value="<?php echo $Rrow->re_id; ?>" />
      </td>
  </tr>
  <tr>
    <td><a class="btn">SAVE</a></td>
    <td><input name="save" id="save" type="submit" /></td>
  </tr>
</table>    
    </form>

1 个答案:

答案 0 :(得分:1)

如果(!isset($_POST['save']))mysql_query代替wp_query,我认为您的问题就在于此,请尝试这样

if (isset($_POST['save'])) {
    if (wp_query("UPDATE wp_domain SET domain='$domain', appointmenttime_setting='$appointment' WHERE re_id=$rid")){
       header( 'Location:http://localhost/thepost/?page_id=17' ) ;
       exit;
    }
}