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.

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

报告相同问题?