simple update record with loop

Discussion in 'PHP' started by zoreli, Jan 26, 2010.

  1. #1
    Hi

    I have two pages, editCategories, and editSubCategories. At this time, I am sending the data (from the form) on two different pages , editCategoriesSave and editSubCategoriesSave using the post method and I am updating record there.

    I would like to have one page for updating records instead of two, named editRecordsSave where I can loop trough the posted data from any of the pages and make an update.

    I will of course post the table name trough the form using hidden field, so I can know in which table to make an update.

    My problem is how to make a loop which will take field names and make an update query on base on posted data.

    Anyone can post some code example, or link where I can learn how to do this?

    Regards, Zoreli
     
    zoreli, Jan 26, 2010 IP
  2. Desire

    Desire Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you want to update a query from form post
    
    $var = $_POST['myvar'];
    
    // make sql connection
    mysql_query("UPDATE `table` set field='".mysql_real_escape_string($var)."'");
    
    Code (markup):
     
    Desire, Jan 26, 2010 IP