dongsu1539 2010-03-24 14:24
浏览 51
已采纳

在文章表中上传图像后存储image_id

According to this question I succeeded to create upload image, but now I need to store the image_id into another table called articles. I do not know if this is correct, but I tried to select the image_id from table image like this

$select_image=mysql_query("select image_id from image where image_name = $fileName") or die(mysql_error());

and fetch the result to my article insert query like this

$fetch=mysql_fetch_array($select_image);

$query=mysql_query("insert into articles (article_name,article_category,article_subcategory,article_body,article_summary,article_tags,article_photo,article_timedate) values ('$article_title','$CategoryID','$ProductID','$article_body','$article_summary','$fetch[image_id]','$time')") or die ('Error, Query Faild'.mysql_error());

Is this correct ? The mysql_error keeps saying

Unknown column 'Penguins.jpg' in 'where clause'

  • 写回答

4条回答 默认 最新

  • dongshi1880 2010-03-24 14:35
    关注

    you can select the last inserted id by calling

    SELECT LAST_INSERT_ID()
    

    instead of

    select image_id from image where image_name = $fileName
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大