Record Update

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raamay
    New Member
    • Feb 2007
    • 107

    Record Update

    Hi Experts, here i come again and wanna ask how we can perform record update in PHP & MySQL without passing the id in the URL for the $_GET method to be used in the processing page. I mean I have records of tenders displayed in a page and each of the records are hyper linked to edit and delete links. And at present what i am doing is embedding id in the URL i.e
    Code:
    <a href=edittender.php?id=$id>Edit</a>
    . Now, i dont want the id to be embedded in the URL and instead want any other methods to be applied to get this workdone. Can you all advice me how i can go about?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    use the POST method, though this requires either form submission or AJAX procedures.

    regards

    Comment

    • raamay
      New Member
      • Feb 2007
      • 107

      #3
      thankyou but i am not sure how POST can be used in this situation. Can i have an example please?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Code:
        <form action="edittender.php" method="post" accept-encoding="UTF-8">
            <input type="hidden" name="id" value="id_to_submit">
            <input type="submit" name="send" value="send request">
        </form>

        Comment

        • raamay
          New Member
          • Feb 2007
          • 107

          #5
          sorry but i think you didnt understand me. well, i please see my code below:
          Code:
          <?php
          $q= "SELECT * FROM ".TABLE." order by field";	
          		         				   
          $result_ = $database->query($q_);
          
          $num_rows_ = mysql_numrows($result_);
          
          for($j=0; $j<$num_rows_; $j++) {                  
               $id = mysql_result($result_,$j,"id");
               $tender = mysql_result($result_,$j,"tender");
          ?>
          <table>
          <tr>
          <td><?php echo $tender; ?></td>
          <td><a href="edittender.php?id=$id">Edit</a>
          </tr>
          </table>
          <?php
          }
          ?>
          The code above can generate all records available in a table and each of it has a EDIT link. Now what i meant to say was that i dont want the id to be passed in the URL which i have done at present. In this case i can't use a form with buttion to pass the id for a POST method.
          Last edited by Markus; Feb 19 '09, 01:17 PM. Reason: Changed [quote] tags to [code].

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            - butts in.

            Then your other option is AJAX. Although, I don't understand your issue with using GET.

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              Originally posted by raamay
              In this case i can't use a form with buttion to pass the id for a POST method.
              why not?

              does it matter if you use a button (form) or a link (href) to trigger the edit? I could have named the button EDIT to make that clearer (but I've had little time, so...)

              Comment

              • TheServant
                Recognized Expert Top Contributor
                • Feb 2008
                • 1168

                #8
                To submit forms without having to click a submit button your best bet as has been said twice is AJAX. PHP will do your server side stuff but if there is a problem on the client side (eg. submittting a form in a fancy way) you want to go javascript/AJAX.

                Comment

                • Dormilich
                  Recognized Expert Expert
                  • Aug 2008
                  • 8694

                  #9
                  Originally posted by TheServant
                  To submit forms without having to click a submit button your best bet as has been said twice is AJAX.
                  that's a rather complicated way of submitting a form.... and kind of spoils the intention a form.

                  the only thing is that you (normally) don't leave the page with AJAX, whereas a link will make you leave the page (so does a form).

                  but still I've not been told why a form is here impossible to use. I'd really like to know that.

                  Comment

                  • Atli
                    Recognized Expert Expert
                    • Nov 2006
                    • 5062

                    #10
                    Hi.

                    What I am wondering is... what is the point of removing the ID from the URL?

                    Whether you pass it via the URL, a typical form using POST or AJAX, the result is the same.
                    And from a security standpoint, they are all pretty much equal. (Given that you designed the server-side portion properly.)

                    Comment

                    • Dormilich
                      Recognized Expert Expert
                      • Aug 2008
                      • 8694

                      #11
                      Originally posted by Atli
                      What I am wondering is... what is the point of removing the ID from the URL?
                      you can't bookmark it?

                      Comment

                      • Atli
                        Recognized Expert Expert
                        • Nov 2006
                        • 5062

                        #12
                        Originally posted by Dormilich
                        you can't bookmark it?
                        To be hones, that doesn't seem all that important.

                        Presumably, the ability to update records is protected by server-side code, like a login mechanism, and is subject to server-side validation.

                        Simply having the link to the update page and the ID you want to update should not be enough to actually update it. You should need to pass some sort of validation, and you should need to pass valid data.

                        If that is no the case, there are bigger problems here then the method used to pass the ID.

                        Comment

                        • devsusen
                          New Member
                          • Feb 2007
                          • 136

                          #13
                          Originally posted by raamay
                          .......And at present what i am doing is embedding id in the URL i.e . Now, i dont want the id to be embedded in the URL and instead want any other methods to be applied to get this workdone. .....
                          I think this is due to security reasons. IMO first encrypt the id and send it via URL using GET method. In the receiving page(here edittender.php) again decrypt it an process.

                          I prefer to send the value via POST method, though AJAX is good but more complex than using POST or GET method.

                          Comment

                          Working...