简体   繁体   English

select BLOB类型图片,插入到另一个表中

[英]select BLOB type image and insert it to another table

I have two table one is storing basic info with image type is blob and the other table is for attendance table, Now my problem is when i select all the table with basic info with image and insert it to another table the image column is only blank the rest has a value, Hope you can help fix it thanks.我有两个表,一个存储图像类型为 blob 的基本信息,另一个表用于考勤表,现在我的问题是当我 select 所有具有图像基本信息的表并将其插入另一个表时,图像列仅为空白rest 有一个值,希望你能帮助修复它,谢谢。

here is my php code:这是我的 php 代码:

<?php 

include_once('connection.php');
if(isset($_POST['submit0'])){
$rfid = $_POST['rfid'];

$sql = mysqli_query($conn,"select * from stud where rfid_num ='$rfid'");
$count = mysqli_num_rows($sql);

if ($count == 0) {
header("location:notexist.php");

    } else{

while( $row = mysqli_fetch_array($sql)) {
                  $rfid=$row['rfid_num'];
                  $id=$row['id'];
                   $name0 = $row['name'];
                   $course0 = $row['course'];
                  $image = $row['image'];

     $InsertSql = "INSERT INTO student_att(rfid_num,id,name,course,image) VALUES ('$rfid','$id','$name0','$course0','$image')";
        $res = mysqli_query($conn, $InsertSql); 
}
}
}
?> 

这是查询的输出

Instead of executing two separate queries I will suggest you to have a single query which will select from one table and insert into another table. 建议您不要使用单个查询,该查询将从一个表中选择并插入另一个表中,而不是执行两个单独的查询。

Example query: 查询示例:

INSERT INTO table2 (st_id,uid,changed,status,assign_status)
SELECT st_id,from_uid,now(),'Pending','Assigned'
FROM table1

NOTE: It's not good to save images in database. 注意:将图像保存在数据库中不是很好。 We usually keep them in folders and save the path of it in database. 我们通常将它们保存在文件夹中,并将其路径保存在数据库中。

The simplest way to solve your error is by doing like this解决错误的最简单方法是这样做

$image=mysqli_real_escape_string($mysqli,$row['image'];

$mysqli is connection variable. $mysqli 是连接变量。 and then in your query use $image to insert image hope it will helps.然后在您的查询中使用 $image 插入图像希望它会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM