如何将图像从一个 table 插入(或复制)到另一个 table
How can I insert (or copy) an image from one table to another table
我要复制用户头像table
$query = "SELECT * from users WHERE username ='$username'";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($result);
$user_image = $row['image'];
并将用户图片插入推荐 table 作为 ($testimonial_image )
$insert_query = "INSERT INTO testimonials (testimonial_author, testimonial_content, testimonial_image) ";
$insert_query .="VALUES ('$testimonial_author','$testimonial_content','$testimonial_image')";
请问我该怎么做?
当你$user_image = $row['image'];
尝试echo $user_image
看看你是否得到了你期望的数据。
如果您获得了预期的数据,请尝试在
之前将 $testimonial_image=$user_image
添加到您的 php 代码中
$insert_query = "INSERT INTO testimonials
...
这将使变量 $testimonial_image
的值与您已经检索到的 $user_image
的值相同。
如果这不起作用,则一个或两个查询中可能存在 sql 错误。
编辑:以下关于将文件复制到新文件夹的评论:
复制一个苍蝇,这与sql无关:
copy("/images/user_image/".$user_image , "/images/testimonial_image/".$user_image)
我要复制用户头像table
$query = "SELECT * from users WHERE username ='$username'";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($result);
$user_image = $row['image'];
并将用户图片插入推荐 table 作为 ($testimonial_image )
$insert_query = "INSERT INTO testimonials (testimonial_author, testimonial_content, testimonial_image) ";
$insert_query .="VALUES ('$testimonial_author','$testimonial_content','$testimonial_image')";
请问我该怎么做?
当你$user_image = $row['image'];
尝试echo $user_image
看看你是否得到了你期望的数据。
如果您获得了预期的数据,请尝试在
之前将$testimonial_image=$user_image
添加到您的 php 代码中
$insert_query = "INSERT INTO testimonials
...
这将使变量 $testimonial_image
的值与您已经检索到的 $user_image
的值相同。
如果这不起作用,则一个或两个查询中可能存在 sql 错误。
编辑:以下关于将文件复制到新文件夹的评论:
复制一个苍蝇,这与sql无关:
copy("/images/user_image/".$user_image , "/images/testimonial_image/".$user_image)