dongtan8532 2013-08-12 20:14 采纳率: 0%
浏览 12

带有更新查询的未定义偏移通知

I have a form that displays a Selection ID, Selection, and Definition pairing from a database. The form is dynamic...depending on the user, there could be any number of these pairings. Here is an example of three pairings:

Selection ID, Selection, Definition

Selection ID, Selection, Definition

Selection ID, Selection, Definition

The page displays just fine, but if the user wants to edit a Selection or Definition, I receive the following error when the form is submitted (Note: Line 41 is my Update query):

"Notice: Undefined offset: 3 in (link to my php file) on line 41"

I assume that the notice is telling me that the query is not reading the information in my three arrays...but I don't know what I should be putting in my query so it will read properly. Thank you very much for your help.

if(isset($_POST['submit'])){    
    $selection_id = array();
    $selection = array();
    $definition = array();

foreach ($_POST as $key => $value){     
    // If array variable starts with "pd_selection_id_for_" save to $selection_id array, otherwise continue to the next array.  

    if(strpos($key, 'pd_selection_id_for_') !== false){
        $selection_id[] = mysql_real_escape_string($value);
    }else if(strpos($key, 'selection_for_') !== false){
        $selection[] = mysql_real_escape_string($value);
    }else if(strpos($key, 'definition_for_') !== false){
        $definition[] = mysql_real_escape_string($value);
    }
}

// Count one of the arrays to select the paired fields and update the database.

$total = count($definition);

for ($i=1; $i <= $total; $i++){
    // Update query for the paired selections and definitions.
    $query = mysql_query("UPDATE `pd_selections` SET `pd_selection` = '$selection[$i]', `pd_definition` = '$definition[$i]' WHERE `pd_selection_id` = '$selection_id[$i]' ") or die(mysql_error());
}

}

  • 写回答

2条回答 默认 最新

  • drtiwd06558 2013-08-12 20:18
    关注

    Minor syntax error the fix for Line 41 is below:

    $query = mysql_query("UPDATE `pd_selections` SET `pd_selection` = '".$selection[$i]."', `pd_definition` = '".$definition[$i]."' WHERE `pd_selection_id` = '".$selection_id[$i]."'") or die(mysql_error());
    
    评论

报告相同问题?

悬赏问题

  • ¥100 iOS开发关于快捷指令截屏后如何将截屏(或从截屏中提取出的文本)回传给本应用并打开指定页面
  • ¥15 unity连接Sqlserver
  • ¥15 图中这种约束条件lingo该怎么表示出来
  • ¥15 VSCode里的Prettier如何实现等式赋值后的对齐效果?
  • ¥15 流式socket文件传输答疑
  • ¥20 keepalive配置业务服务双机单活的方法。业务服务一定是要双机单活的方式
  • ¥50 关于多次提交POST数据后,无法获取到POST数据参数的问题
  • ¥15 win10,这种情况怎么办
  • ¥15 如何在配置使用Prettier的VSCode中通过Better Align插件来对齐等式?(相关搜索:格式化)
  • ¥100 在连接内网VPN时,如何同时保持互联网连接