doufei3152 2016-05-20 16:11
浏览 12
已采纳

麻烦图像发布和mysql BLOB变量

I have a form for creating employee and I need to store images in my database (using BLOB MySQL datatype). I use this code and I get an error. Is it about this line?

$file=file_get_contents($_FILES["image"]["tmp_name"]);

what is wrong with this code???

if (isset($_POST['submit']))
{


    $name=mysqli_prep($_POST["name"]);
    $family=mysqli_prep($_POST["family"]);
    $id=$_POST["id"];
    $staff_id=$_POST["staff_id"];
    $account_number=$_POST["account_number"];
    $sex=$_POST["sex"];
    $number_of_children=$_POST["number_of_children"];
    $tel=$_POST["tel"];
    $address=$_POST["address"];
    $no=$_POST["no"];
    $working_record=$_POST["working_record"];
    $marital_state=$_POST["marital_state"];
    $employer_id=$_POST["employer_id"];
        $file=file_get_contents($_FILES["image"]["tmp_name"]); 


    $query  ="INSERT INTO Employee (";
    $query .="Name,Family,ID,Staff_ID,Account_Number,Sex,Number_of_Children,";
    $query .="Tel,Address,No,Working_Record,Marital_State,";
    $query .="Employer_ID,Image)";
    $query .=" VALUES (";
    $query .="'{$name}','{$family}',{$id},{$staff_id},{$account_number},";       
    $query .="'{$sex}',{$number_of_children},{$tel},'{$address}',{$no},";
    $query .="'{$working_record}','{$marital_state}',";
    $query .="{$employer_id},'$file')";        
    $result =mysqli_query($connection, $query);

       if(!$result){   
           $_SESSION["message"] ="There were some errors,fill each 
       section carefully";   
           redirect_to("creat_employee.php");
       }
       else{
           $_SESSION["message"]="filling has been done !";

           redirect_to("creat_employee.php");
    }
}
  • 写回答

1条回答 默认 最新

  • dopzc64662 2016-05-20 18:42
    关注

    Finally I found the answer,tried addslashes function (used for sqlinjection) and surprisingly it worked properly

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

报告相同问题?

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 flask项目,怎么使用AJAX传数据库数据到echarts图表的data里,实现异步加载数据。
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题