what do i need to do this

Discussion in 'PHP' started by dougvcd, Mar 21, 2008.

  1. #1
    hi again
    what do i need to populate a form from database and view each record and amend or delete it
    cheers
    Doug
     
    dougvcd, Mar 21, 2008 IP
  2. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #2
    Just create an action flag for the submit button and switch it in the IF POST.


    if($_POST){
    
      $id = $_POST['id'];
      $item1 = $_POST['item1'];
      $item2 = $_POST['item2'];
      $item3 = $_POST['item3'];
    
      mysql_query("UPDATE <TABLE> SET item1 = '" . $item1 . "', item2 = '" . $item2 . "', item3 = '" . $item3 . "' WHERE id = '" . $id . "'");
    
    }
    
    
    
    print "<table>";
    
    $result = mysql_query("SELECT * FROM <TABLE>");
    while($row = mysql_fetch_array($result)){
    
      print "<form>
                   <input type='hidden' name='id' value='" . $row['id'] . "' /><tr>
                  <td>Item 1 : <input name='item1' type='text' value='" . $row['item1'] . "' /></td>
                  <td>Item 2 : <input name='item2' type='text' value='" . $row['item2'] . "' /></td>
                  <td>Item 3 : <input name='item3' type='text' value='" . $row['item3'] . "' /></td>
                  <td><input type='submit' value='edit' /></td>
      </tr></form>";
    
    }
    
    print "</table>";
    PHP:
     
    Weirfire, Mar 21, 2008 IP
  3. dougvcd

    dougvcd Peon

    Messages:
    267
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    sorry not sure what to do with this code as i have very little know how as i am still learning
    cheers
    Doug
     
    dougvcd, Mar 21, 2008 IP
  4. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #4
    No problem Doug. I'd suggest you learn the basics of PHP before you start using databases. :)

    www.php.net
     
    Weirfire, Mar 22, 2008 IP