duanhuau567787 2014-10-13 02:20
浏览 42
已采纳

致命错误PDO异常

I am trying to update mysql with pdo... I have this working on one site but it is not working on a second site. I am getting the follow error no matter which approach I try.

The first site was built live on the net while this one is in wamp... not sure if that would matter.

( ! ) Fatal error: in C:\wamp\www\demo\admin\action\global-settings-css-update.php on line 236 ( ! ) PDOException: in C:\wamp\www\demo\admin\action\global-settings-css-update.php on line 236

<?php

    $level = '../../';
    //include($level.'inc/start.php');

      $db_host = "localhost";  
      $db_username = "xxxxx"; 
      $db_pass = "xxxxx"; 
      $db_name = "demo";

      $db = new PDO('mysql:host='.$db_host.';dbname='.$db_name,$db_username,$db_pass, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ));

            $action = $_POST['action'];                 
            $returnto = $_POST['returnto'];

            $global_id = $_POST['global_id'];       
            $rem_base = $_POST['rem_base']; 
            $base_font_size = $_POST['base_font_size']; 
            $base_line_height = $_POST['base_line_height']; 
            $_POST_width = $_POST['_POST_width'];
            $column_gutter = $_POST['column_gutter']; 
            $default_font_family = $_POST['default_font_family']; 
            $default_font_color = $_POST['default_font_color'];
            $default_font_style = $_POST['default_font_style'];
            $default_font_weight = $_POST['default_font_weight'];            
            $primary = $_POST['primary']; 
            $primary_lighter = $_POST['primary_lighter']; 
            $primary_darker = $_POST['primary_darker']; 
            $second_accent = $_POST['second_accent']; 
            $second_accent_lighter = $_POST['second_accent_lighter'];
            $second_accent_darker = $_POST['second_accent_darker']; 
            $third_accent = $_POST['third_accent']; 
            $third_accent_lighter = $_POST['third_accent_lighter']; 
            $third_accent_darker = $_POST['third_accent_darker']; 
            $alert = $_POST['alert'];
            $alert_lighter = $_POST['alert_lighter']; 
            $alert_darker = $_POST['alert_darker']; 
            $success = $_POST['success']; 
            $success_lighter = $_POST['success_lighter']; 
            $success_darker = $_POST['success_darker'];     
            $warning = $_POST['warning']; 
            $warning_lighter = $_POST['warning_lighter']; 
            $warning_darker = $_POST['warning_darker']; 
            $pg_bg_color = $_POST['pg_bg_color']; 
            $pg_has_gradient_bg = $_POST['pg_has_gradient_bg']; 
            $pg_bg_gradient_direction = $_POST['pg_bg_gradient_direction']; 
            $pg_bg_which_flow = $_POST['pg_bg_which_flow'];     
            $pg_bg_light_percent = $_POST['pg_bg_light_percent']; 
            $pg_bg_dark_percent = $_POST['pg_bg_dark_percent']; 
            $pg_has_bg_image = $_POST['pg_has_bg_image']; 
            $pg_bg_img = $_POST['pg_bg_img']; 
            $pg_bg_repeat = $_POST['pg_bg_repeat']; 
            $pg_bg_image_positioned = $_POST['pg_bg_image_positioned']; 
            $pg_bg_hor_align = $_POST['pg_bg_hor_align']; 
            $pg_bg_vert_align = $_POST['pg_bg_vert_align'];         

            if($action == 'add'){   

                $insertq = $db->prepare(
                'INSERT INTO THE-TABLE (
                    rem_base,
                    base_font_size,
                    base_line_height,
                    row_width,
                    column_gutter,
                    default_font_family,
                    default_font_color,
                    default_font_style,
                    default_font_weight,                    
                    primary,
                    primary_lighter,
                    primary_darker,
                    second_accent,
                    second_accent_lighter,
                    second_accent_darker,
                    third_accent,
                    third_accent_lighter,
                    third_accent_darker,
                    alert,
                    alert_lighter,
                    alert_darker,
                    success,
                    success_lighter,
                    success_darker,
                    warning,
                    warning_lighter,
                    warning_darker,
                    pg_bg_color,
                    pg_has_gradient_bg,
                    pg_bg_gradient_direction,
                    pg_bg_which_flow,
                    pg_bg_light_percent,
                    pg_bg_dark_percent,
                    pg_has_bg_image,
                    pg_bg_img,
                    pg_bg_repeat,
                    pg_bg_image_positioned,
                    pg_bg_hor_align,
                    pg_bg_vert_align        
                )

                VALUES (?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,?,?)');
                $insertq->execute(array(
                    $rem_base,
                    $base_font_size,
                    $base_line_height,
                    $row_width,
                    $column_gutter,
                    $default_font_family,
                    $default_font_color,
                    $default_font_style,
                    $default_font_weight,                   
                    $primary,
                    $primary_lighter,
                    $primary_darker,
                    $second_accent,
                    $second_accent_lighter,
                    $second_accent_darker,
                    $third_accent,
                    $third_accent_lighter,
                    $third_accent_darker,
                    $alert,
                    $alert_lighter,
                    $alert_darker,
                    $success,
                    $success_lighter,
                    $success_darker,
                    $warning,
                    $warning_lighter,
                    $warning_darker,
                    $pg_bg_color,
                    $pg_has_gradient_bg,
                    $pg_bg_gradient_direction,
                    $pg_bg_which_flow,
                    $pg_bg_light_percent,
                    $pg_bg_dark_percent,
                    $pg_has_bg_image,
                    $pg_bg_img,
                    $pg_bg_repeat,
                    $pg_bg_image_positioned,
                    $pg_bg_hor_align,
                    $pg_bg_vert_align       
                ));

                $msg = 's|The '.$table_title.': '.$industry.' has been added to the database.';             
            }


            elseif($action == 'edit'){

            $updateq=$db->prepare("update global_settings set
                    global_id=:global_id,
                    rem_base=:rem_base,
                    base_font_size=:base_font_size,
                    base_line_height=:base_line_height,
                    row_width=:row_width,
                    column_gutter=:column_gutter,
                    default_font_family=:default_font_family,
                    default_font_color=:default_font_color,
                    default_font_style=:default_font_style,
                    default_font_weight=:default_font_weight,
                    primary=:primary,
                    primary_lighter=:primary_lighter,
                    primary_darker=:primary_darker,
                    second_accent=:second_accent,
                    second_accent_lighter=:second_accent_lighter,
                    second_accent_darker=:second_accent_darker,
                    third_accent=:third_accent,
                    third_accent_lighter=:third_accent_lighter,
                    third_accent_darker=:third_accent_darker,
                    alert=:alert,
                    alert_lighter=:alert_lighter,
                    alert_darker=:alert_darker,
                    success=:success,
                    success_lighter=:success_lighter,
                    success_darker=:success_darker,
                    warning=:warning,
                    warning_lighter=:warning_lighter,
                    warning_lighter=:warning_lighter,
                    pg_bg_color=:pg_bg_color,
                    pg_has_gradient_bg=:pg_has_gradient_bg,
                    pg_bg_gradient_direction=:pg_bg_gradient_direction,
                    pg_bg_which_flow=:pg_bg_which_flow,
                    pg_bg_light_percent=:pg_bg_light_percent,
                    pg_bg_dark_percent=:pg_bg_dark_percent,
                    pg_has_bg_image=:pg_has_bg_image,
                    pg_bg_img=:pg_bg_img,
                    pg_bg_repeat=:pg_bg_repeat,
                    pg_bg_image_positioned=:pg_bg_image_positioned,
                    pg_bg_hor_align=:pg_bg_hor_align,
                    pg_bg_vert_align=:pg_bg_vert_align

                    where global_id=$global_id");           

                    $updateq->bindParam(':global_id',$global_id,PDO::PARAM_STR);
                    $updateq->bindParam(':rem_base',$rem_base,PDO::PARAM_STR);
                    $updateq->bindParam(':base_font_size',$base_font_size,PDO::PARAM_STR);
                    $updateq->bindParam(':base_line_height',$base_line_height,PDO::PARAM_STR);
                    $updateq->bindParam(':row_width',$row_width,PDO::PARAM_STR);
                    $updateq->bindParam(':column_gutter',$column_gutter,PDO::PARAM_STR);
                    $updateq->bindParam(':default_font_family',$default_font_family,PDO::PARAM_STR);
                    $updateq->bindParam(':default_font_color',$default_font_color,PDO::PARAM_STR);
                    $updateq->bindParam(':default_font_style',$default_font_style,PDO::PARAM_STR);
                    $updateq->bindParam(':default_font_weight',$default_font_weight,PDO::PARAM_STR);
                    $updateq->bindParam(':primary',$primary,PDO::PARAM_STR);
                    $updateq->bindParam(':primary_lighter',$primary_lighter,PDO::PARAM_STR);
                    $updateq->bindParam(':primary_darker',$primary_darker,PDO::PARAM_STR);
                    $updateq->bindParam(':second_accent',$second_accent,PDO::PARAM_STR);
                    $updateq->bindParam(':second_accent_lighter',$second_accent_lighter,PDO::PARAM_STR);
                    $updateq->bindParam(':second_accent_darker',$second_accent_darker,PDO::PARAM_STR);
                    $updateq->bindParam(':third_accent',$third_accent,PDO::PARAM_STR);
                    $updateq->bindParam(':third_accent_lighter',$third_accent_lighter,PDO::PARAM_STR);
                    $updateq->bindParam(':third_accent_darker',$third_accent_darker,PDO::PARAM_STR);
                    $updateq->bindParam(':alert',$alert,PDO::PARAM_STR);
                    $updateq->bindParam(':alert_lighter',$alert_lighter,PDO::PARAM_STR);
                    $updateq->bindParam(':alert_darker',$alert_darker,PDO::PARAM_STR);
                    $updateq->bindParam(':success',$success,PDO::PARAM_STR);
                    $updateq->bindParam(':success_lighter',$success_lighter,PDO::PARAM_STR);
                    $updateq->bindParam(':success_darker',$success_darker,PDO::PARAM_STR);
                    $updateq->bindParam(':warning',$warning,PDO::PARAM_STR);
                    $updateq->bindParam(':warning_lighter',$warning_lighter,PDO::PARAM_STR);
                    $updateq->bindParam(':warning_lighter',$warning_lighter,PDO::PARAM_STR);
                    $updateq->bindParam(':pg_bg_color',$pg_bg_color,PDO::PARAM_STR);
                    $updateq->bindParam(':pg_has_gradient_bg',$pg_has_gradient_bg,PDO::PARAM_STR);
                    $updateq->bindParam(':pg_bg_gradient_direction',$pg_bg_gradient_direction,PDO::PARAM_STR);
                    $updateq->bindParam(':pg_bg_which_flow',$pg_bg_which_flow,PDO::PARAM_STR);
                    $updateq->bindParam(':pg_bg_light_percent',$pg_bg_light_percent,PDO::PARAM_STR);
                    $updateq->bindParam(':pg_bg_dark_percent',$pg_bg_dark_percent,PDO::PARAM_STR);
                    $updateq->bindParam(':pg_has_bg_image',$pg_has_bg_image,PDO::PARAM_STR);
                    $updateq->bindParam(':pg_bg_img',$pg_bg_img,PDO::PARAM_STR);
                    $updateq->bindParam(':pg_bg_repeat',$pg_bg_repeat,PDO::PARAM_STR);
                    $updateq->bindParam(':pg_bg_image_positioned',$pg_bg_image_positioned,PDO::PARAM_STR);
                    $updateq->bindParam(':pg_bg_hor_align',$pg_bg_hor_align,PDO::PARAM_STR);
                    $updateq->bindParam(':pg_bg_vert_align',$pg_bg_vert_align,PDO::PARAM_STR);

        $updateq->execute();

        $msg = 's|The '.$table_title.': '.$industry.' has been updated in the database.';
        }
        echo '<Script language="javascript">window.location="'.$level.'admin/global-settings-css-action.php?msg='.$msg.'"</script>';            
?>

Thanks, Pete

  • 写回答

1条回答 默认 最新

  • douhanxujiuji6098 2014-10-13 02:58
    关注

    Firstly, primary is MySQL reserved word:

    The other option is to name it to something other than primary.


    $insertq = $db->prepare(
                    'INSERT INTO THE-TABLE (
                        rem_base,
                        base_font_size,
                        base_line_height,
                        row_width,
                        column_gutter,
                        default_font_family,
                        default_font_color,
                        default_font_style,
                        default_font_weight,                    
                        `primary`,
    

    and in:

    $updateq=$db->prepare("update global_settings set
                        global_id=:global_id,
                        rem_base=:rem_base,
                        base_font_size=:base_font_size,
                        base_line_height=:base_line_height,
                        row_width=:row_width,
                        column_gutter=:column_gutter,
                        default_font_family=:default_font_family,
                        default_font_color=:default_font_color,
                        default_font_style=:default_font_style,
                        default_font_weight=:default_font_weight,
                        `primary`=:primary,
    

    I'm unsure about $_POST_width = $_POST['_POST_width']; which may have adverse/unexpected effects since superglobals start with $_ (8 of 9 actually).

    I suggest you rename $_POST_width to something other than starting with $_.

    I can't be 100% sure about that, but it's worth trying if you're still getting errors.

    You will need to tell me how that's being pulled in from.

    From what I can tell, it may need to be $row_width = $_POST['width']; depending on your form element's name.

    You will need to provide me with your HTML form in order to be certain.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧