[英]How can i use SQL Select Insert to copy rows from one table to another
[英]How can I insert (or copy) an image from one table to another table
我想從用戶表中復制用戶圖像
$query = "SELECT * from users WHERE username ='$username'";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_assoc($result);
$user_image = $row['image'];
並將用戶圖像作為($ 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
以查看是否已獲得所需的數據。
如果您有所需的數據,請嘗試在您的php代碼中添加$testimonial_image=$user_image
$insert_query = "INSERT INTO testimonials
...
這將使變量$testimonial_image
的值與您已檢索的$user_image
的值相同。
如果這不起作用,則在一個或兩個查詢中可能存在sql錯誤。
編輯:關於將文件復制到新文件夾的以下注釋:
要復制flie,與sql無關:
copy("/images/user_image/".$user_image , "/images/testimonial_image/".$user_image)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.