dongzhi6463 2013-02-26 17:40
浏览 72

在表单提交后返回/重定向到锚定的div

as far as i studied in several posts, the following form should return to the div #CCC after submission

$editFormAction = $_SERVER['PHP_SELF']."#CCC";

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "formX")) { 
$updateSQL = sprintf("UPDATE foodtable SET food_preference=%s  WHERE food_id=%s",    
                       GetSQLValueString($_POST['food_preference'], "text"),
                       GetSQLValueString($_POST['food_id'], "int"));

  mysql_select_db($database_XYZ, $XYZ);
  $Result1 = mysql_query($updateSQL, $XYZ) or die(mysql_error());

  $updateGoTo = "preference.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
      }
  header(sprintf("Location: %s", $updateGoTo));
    exit ();
}

<body>

<div id ="AAA">
<p>Some text</p>
</div>

<div id ="BBB">
<p>Some more text</p>
</div>

<div id ="CCC">
     <form action="<?php echo $editFormAction; ?>" method="post" name="formX" id="formX">
     <table align="center">
     <tr valign="baseline">
     <td align="right" nowrap="nowrap">Update Food Name:</td>
     <td><input type="text" name="food_name" value="" size="32" /></td>
     </tr>
     <tr valign="baseline">
     <td nowrap="nowrap" align="right">
     <input type="hidden" name="MM_update" value="formX" />
     <input type="hidden" name="food_id" value="<?php echo $query['food_id']; ?>" />
     </td>
     <td>
     <input type='submit' value='Update Food Name'/>"
    </td>
    </tr>
    </table>
   </form>
</div>

</body>

but it isn't returning to the div #CCC on submission. is there anything lacking in the above blocks of code?

thanks,

  • 写回答

1条回答 默认 最新

  • douyi7055 2013-02-26 17:45
    关注

    The form is submitting to yourpage#CCC but the line

    header(sprintf("Location: %s", $updateGoTo));
    

    Is redirecting you, after you have processed the form.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分