doucheng7534 2018-04-08 17:07
浏览 27
已采纳

如何使用jQ以多用途形式回显db值?

I have a form that appears in a popup when the user presses Upload. It uses the upload.php file.
The form contains title, a photo file input, a description and a category. The form also uploads the submitter's id to my db.
I want the same form to popup when the user presses Edit in one of his own uploaded photos, but with the fields populated with data from the relevant row, probably using a lookup.php file.

I looked up how to do it, but results assume the form does not perform any other function other than being populated with existing data. Any ideas how I can perform what I want?

I do have the code, but first I'd like to understand the concept.

  • 写回答

1条回答 默认 最新

  • doukuipai8544 2018-04-08 17:45
    关注

    At simplest, your "upload" script needs to optionally accept an upload id. A typical way of handling this would be either in a get param or a hidden form element. Get is more appropriate and simpler for this use case in my opinion. So when you click edit, the edit button should already be prepopulated with:

    upload.php?id=38
    

    In your upload script, at the top, you will check to see if

    if (isset($_GET['id'])) {
       // Query database for picture
       // If found check if this user owns or is permitted to edit this photo
    
    }
    

    At this point, if you've successfully found the photo, you can pre-populate the form fields you want to allow them to change. Again, the only concern is tampering. In this case, I would probably use a hidden input with the upload id, but check that the user owns that upload before you allow them to change it.

    The portion that saves the script simply needs to be altered so that if you submit the form with an existing upload id, your database SQL peforms an UPDATE rather than a INSERT.

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

报告相同问题?

悬赏问题

  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢