need help with updates

Discussion in 'PHP' started by saturn100, Dec 1, 2011.

  1. #1
    I am looking for away a person can edit a particular row in a data base via a form
    that it connects to a database then table then row (BY ID) and then a user can update.change the information in that row
    I have been looking online but cant find a simple and full tutorial on it

    Any help welcomed

    ie it will added to a sessions page
     
    saturn100, Dec 1, 2011 IP
  2. kids

    kids Active Member

    Messages:
    411
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    68
    #2
    Try this
     
    ...
    If ($_GET['edit']){
        $id = $_GET['edit'];
        $sql = "SELECT * FORM table WHERE id = '$id'";
        // Run query and get back $data
       
       $f1 = $data['f1'];
        ...
    } else if (isset($_POST['submit']) && is_member) {
    // is_member is session variable return true if member online,...
     $sql = "UPDATE table SET
               f1 = '$f1',
               ....
               WHERE id = '$id'";
    }
    ...
    
    Code (markup):
    design form as you want.

    Do more to make it complete. Maybe this is on your way.
     
    kids, Dec 1, 2011 IP
  3. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #3
    mfscripts, Dec 2, 2011 IP
  4. webdesignbd

    webdesignbd Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi
    Why Mr. Kids use $_GET method in if function & $_POST method in if...else function. But if function is true then data have less secure from if...else function. So I thing it is not really perfect way to edit a row.

    :) Gd day.

    Munni
     
    webdesignbd, Dec 2, 2011 IP
  5. imtiyaz.jmi

    imtiyaz.jmi Greenhorn

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    21
    #5
    When u are editing a row, it means that row is already into database and will have an id(primary key). When are you posting form put that id into <input type="hidden" name="id" id="id" value="<?php echo $id; ?>">. When you click on update

    write the query as update table .... where id=$_REQUEST['id'];
     
    imtiyaz.jmi, Dec 3, 2011 IP