Okay this is a tough one.
I want to make a dynamic mysql update query that takes results entered into a series of text boxes (changes from page to page) and then updates that record in my Mysql table.

the name of the form fields are $value[$x]
where 1 <= $x <= Total number of fields

=======================================

$query = "UPDATE ".$table." WHERE ".$table_headers[0]." = ".$id."
VALUES

=======================================

I have gotten this far, but don't know where to go next.
check out
www.filterseven.co.uk/admin/index.php
and if you check a table, and choose an edit query on one of the records to see what i am trying to do.

thank's for your time!
cheers,
Dave

    Yeah i considered that, but you see The Update query will have a different number of fields depending on what table you have selected.

    Is there anyway to do like a for loop to create the values part of the query then combine it with the first part of the string.

    something like

    ======================================
    $query1 = "UPDATE ".$table." SET " ;

    $query2 = ( for ($x=0; $x <=$num_headers; $x++){
    ". $table_headers[$x] . "=" . $values[$x] . " , "
    }) ;

    $query = $query1.$query2 ;

    $result = msql_query ($query) ;
    etc...

      hi,

      something like

      $query = "update table_name set ";

      for ($i = 0; $i < $end_of_vars; $i++){
      $query = $query . $var . "\"$key\"";
      }

      and then just execute the query. I am not sure if this run because i did not test it but it should give you an idea. Also you want me to careful with this type of this because people could use it against you.

      Say for example they change the table_name or the column field this could be bad.

      • Justin
        Write a Reply...