安全模式sql php问题

时间:2017-05-12 11:39:52

标签: php mysql sql

我有php / mysql的问题。当我想用php更新或删除表中的条目时,我有这个错误:

  

错误代码:1175。您正在使用安全更新模式,但您尝试过   更新没有使用KEY列的WHERE的表要禁用安全性   模式,切换首选项中的选项 - > SQL查询并重新连接。

我尝试将MYSQL_SAFE_UPDATES设置为0,但仍然无效。

我还阅读了这篇文章:MySQL error code: 1175 during UPDATE in MySQL Workbench并没有解决我的问题

有人有小费吗?

代码:

$sql2 = "update $table set ";
           $sql3 = "insert into $table"."_ (";
           $find;
           foreach ($arr2 as $name) {
                if($name != "user"){
                    $id2 ='inp'.$k;
                    if(isset($_POST[$id2])){ 
                        $val = $_POST[$id2];
                        $sql3.= $name.",";
                    }
                    $k++;
                }
                else{
                    $find = $k;
                    //$k++;
                }
           }
           $sql3 = substr($sql3,0,-1);
           $sql3.=") ";
           $sql3.= " values( ";
           $check = "select * from $table where ";
           $k=0;
           $f=0;
           foreach ($arr as $name) {
                    if($arr2[$k] != "user"){
                        $id2 ='inp'.$f;
                        if(isset($_POST[$id2])){
                            $val = $_POST[$id2];
                           // echo $val."  ";
                            if(isset($_POST[$id2])){
                                if ((strpos($name, 'int') !== false || strpos($name,'float') !== false) && (!empty($val) && is_numeric ($val))){
                                    $sql2.= $arr2[$k]."=".$val.", ";
                                    $check.= $arr2[$k]."=".$val." and ";
                                    $sql3.= $val.",";
                                }
                                else{
                                    if(strpos($name, 'varchar') !== false){
                                        $sql2.= $arr2[$k]."='".$val."', ";
                                        $check.= $arr2[$k]."='".$val."' and ";
                                        $sql3.= "'".$val."',";
                                    }
                                    else{
                                        if ((strpos($name, 'int') !== false || strpos($name,'float') !== false) && (!empty($val) && !is_numeric ($val))){
                                           goto error;
                                           break;
                                        }
                                    }
                                }
                            }
                            else{
                               $sql2.=$arr2[$k]."="."NULL,";
                               $check.=$arr2[$k]."="."NULL and ";
                               $sql3.="NULL,";
                            }
                            $f++;
                        }
                    }
                    $k++;
           }
           $use = $_SESSION['user'];
           $check = substr($check,0,-5);
           $check.=";";
           $sth = $conn->prepare("$check");
           $sth->execute();
           $row = $sth->fetch(PDO::FETCH_ASSOC);
           if(!$row){
               $sql2 = substr($sql2, 0, -2);
               $sql2.=" where ";
               $i = 0;
               $j=0;
               $bool = 0;
               if(isset($_SESSION['tab'])){
                   foreach ($arr as $name) {
                       if($arr2[$i] != "user"){
                           $id2 ='inp'.$j;
                           if(isset($_POST[$id2])){
                              $val = $_SESSION['tab'][$j];
                              if($id2 != ""){
                                   $sql2.= $arr2[$i]."=";
                                   if ((strpos($name, 'int') !== false || strpos($name,'float') !== false) && (!empty($val) && is_numeric ($val))){
                                       $sql2.= $val." and ";
                                   }
                                   else{
                                        if(strpos($name,'varchar') !== false){
                                            $sql2.= "'".$val."' and ";
                                        }
                                        else{
                                            if(empty($val)){
                                                $sql2.= $arr2[$i]." IS NULL and ";
                                            }
                                            else{
                                                if ((strpos($name, 'int') !== false || strpos($name,'float') !== false) && (!empty($val) && !is_numeric ($val))){
                                                    goto error;
                                                    break;
                                                }
                                            }
                                        }
                                   }
                              }
                              unset($_POST[$id2]);
                              $j++;
                          }
                          else{
                               $sql2.= $arr2[$i]." IS NULL and ";
                          }
                        }
                      $i++;
                   }
                   unset($_SESSION['tab']);
               }
               else{
                    echo "ici";
                   goto error;
                   $bool = -1;
               }
               if($bool != -1){
                   $sql2 = substr($sql2,0,-5);
                   $sql2.=";";
                   try{
                       $sth = $conn->prepare("$sql2");
                       $sth->execute();
                   }
                   catch(Exception $e){
                        echo $e;
                   }
                   $sql3 = substr($sql3,0,-1);
                   $sql3.=");";
                   try{
                       $sth = $conn->prepare("$sql3");
                       $sth->execute();
                   }
                   catch(Exception $e){
                        echo $e;
                   }
                   echo $sql2."<br/>".$sql3."<br/>";
                   unset($_POST['sub']);
                   //redirect('database.php', 303);
              }
            }
            else{
                echo $check;
                goto error;
            }
        }
        error : 
            if(isset($e))
                echo $e;

这是echo声明:

更新recherche set date ='erzerze',coordonnees ='zeraezr',typeMilieu ='Forêt',Responsable ='azerazer',observateurPreleveur ='azerazer',projet ='azerazer',observation ='Flore',prelevements = 'Flore',experimentations ='Identification',commentaires ='',test ='rtrt',其中date ='erzerze'和coordonnees ='zeraezr'和typeMilieu ='Forêt'和Responsable ='azerazer'和observateurPreleveur ='azerazer'和projet ='azerazer'和观察='Flore'和prelevements ='Flore'和experimentations ='Identification'和commentaires =''和test ='';

0 个答案:

没有答案