Page 1 of 1

updating a form with multiple fields prob!

Posted: Mon Aug 27, 2007 12:33 pm
by Addos
I wonder if somebody can help me with this form.
I want to be able to update my database table by using a sort order where I can arrange the order of a list by using numbers. I have no problem in querying the database and retuning the values using the following script.

Code: Select all

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
    <table align="center">    
      <tr valign="baseline">
        <td>Solo Title:</td>
        <td>Sort:</td>
      </tr>
	    <?php do { ?>
      <tr valign="baseline">
        <td><?php echo $row_GetSolo_Inst['Solo_Title']; ?></td>
        <td><input type="text" name="sort" value="<?php echo $row_GetSolo_Inst['sort']; ?>" size="10"></td>
      </tr>	      
    <input type="hidden" name="solo_ID" value="<?php echo $row_GetSolo_Inst['solo_ID']; ?>">
      <?php } while ($row_GetSolo_Inst = mysql_fetch_assoc($GetSolo_Inst)); ?>
      <tr valign="baseline">
        <td><input type="submit" value="Update record"></td>
        <td>&nbsp;</td>
      </tr>
    </table>
<input type="hidden" name="MM_update" value="form1">
  </form>
The problem is that I can’t get the form to process the changes that are made and I know that my problem is to do with trying to have one ‘Submit’ button. I can get this to work using a simple form using the following where one form field is being updated.

Code: Select all

$updateSQL = sprintf("UPDATE compositions_solo SET sort=%s WHERE solo_ID=%s",
                       GetSQLValueString($_POST['sort'], "int"),
                       GetSQLValueString($_POST['solo_ID'], "int"));

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
    <table align="center">
    
      <tr valign="baseline">
        <td>Solo Title:</td>
        <td>Sort:</td>
      </tr>
	      <tr valign="baseline">
        <td><?php echo $row_GetSolo_Inst['Solo_Title']; ?></td>
        <td><input type="text" name="sort" value="<?php echo $row_GetSolo_Inst['sort']; ?>" size="10"></td>
      </tr>
	      
    <input type="hidden" name="solo_ID" value="<?php echo $row_GetSolo_Inst['solo_ID']; ?>">
      
      <tr valign="baseline">
        <td><input type="submit" value="Update record"></td>
        <td>&nbsp;</td>
      </tr>
    </table>
<input type="hidden" name="MM_update" value="form1">
  </form>
However once I try to introduce multiple fields to update then the forms fails. So can anyone tell/show me how I can set up a form so that it accepts multiple changes and have one submit button to do the updating

This is a print out of the first code above incase it’s of any value.
Thanks a mil

Code: Select all

<form method="post" name="form1" action=”self.php">
   
 Voces Críticas (2004) <input type="text" name="sort" value="6" size="10">
      <input type="hidden" name="solo_ID" value="7

Canción y Tango (2004) <input type="text" name="sort" value="6" size="10">
    <input type="hidden" name="solo_ID" value="8">

Twelve Études (2004) <input type="text" name="sort" value="8" size="10">	      
    <input type="hidden" name="solo_ID" value="9">

 <input type="submit" value="Update record">
        <input type="hidden" name="MM_update" value="form1">
  </form>

just change the name

Posted: Mon Aug 27, 2007 12:53 pm
by yacahuma

Code: Select all

<?
if (isset($_POST['sortbtn']))
 print_r($_POST['sort']);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Page title</title>
</head>
<body>

<form action="test30.php" method="post">
<input type="text" name="sort[70]"  />
<input type="text" name="sort[80]"  />
<input type="text" name="sort[90]"  />
<input type="text" name="sort[100]"  />
<input type="submit" name="sortbtn" />
</form>

</body>
</html>
sort is now an array. 70,80,90,100 are the ids.
Use that information to create your sql statement

sample output
Array ( [70] => 1 [80] => 5 [90] => 4 [100] => 89 )