Jump to content

Associative array and post method to update mysql table?


Dan06

Recommended Posts

I'm trying to use information from an associative array (which is stored in a table) to update a mysql table via the post method. The code below is what I'm using:

 

if ((isset($_POST["SubmitProList"])) && (isset($_POST["SubmitServList"])) && ($_POST["SubmitProList"] && ($_POST["SubmitServList"]) == "ListingForm")) {
  $updateSQL = sprintf("UPDATE businessprofile SET ProductType=%s, ServiceType=%s WHERE UtilistId=" . "'" . $_SESSION['UtilistReg'] . "'",
                       GetSQLValueString($_POST["$row_ProdType['TypeName']"], "text"),
                       GetSQLValueString($_POST["$row_ServType['TypeName']"], "text"));

 

When I submit the form I get the error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in D:\Apache\htdocs\listregister.php on line 103

 

When I remove the $_POST method, i.e.

 ...
        GetSQLValueString($row_ProdType['TypeName'], "text"),
        GetSQLValueString($row_ServType['TypeName'], "text"));

The form does nothing - nothing updates, no error messages, absolutely nothing changes. Anyone have a solution or suggestion to my problem? Thanks.

 

 

 

The GetSQLValueString function puts ' ' around the values that are represented by %s in the sprintf.

 

The hunch I have is that the way I'm using the associative array with the post method is some how wrong. Can anyone tell me if I'm using the $row_ProdType['TypeName'] & $row_ServType['TypeName'] in the update query incorrectly? Below is my update query code:

 

if ((isset($_POST["SubmitProdList"])) && (isset($_POST["SubmitServList"])) && ($_POST["SubmitProdList"] && ($_POST["SubmitServList"]) == "ListingForm")) {
  $updateSQL = sprintf("UPDATE businessprofile SET ProductType=%s, ServiceType=%s WHERE Id=" . "'" . $_SESSION['Reg'] . "'",
                       GetSQLValueString($row_ProdType['TypeName'], "text"),
                       GetSQLValueString($row_ServType['TypeName'], "text")); 

 

Below is the code for the dynamic form:

<?php do { ?>
                <tr>
                  <td><form action="<?php echo $editFormAction; ?>" id="ProdTypeSelection" name="ProdTypeSelection" method="post"><input type="checkbox" name = "$row_ProdType['TypeName']" id="$row_ProdType['TypeName']" value="$row_ProdType['TypeName']"/>
                  		<input name="SubmitProdList" type="hidden" id="SubmitProdList" value="ListingForm" />
                  </form></td>
                  <td><?php echo $row_ProdType['TypeName']; ?></td>
                </tr>
                <?php } while ($row_ProdType = mysql_fetch_assoc($ProdType)); ?>
            </table>
            <p> </p>
          </div>
          <div id="ServTbl">
            <p><strong>What Type of Services?</strong></p>
            <p> </p>
            
            <table border="1" align="center">
              
              <?php do { ?>
                <tr>
                  <td><form action="<?php echo $editFormAction; ?>" id="ServTypeSelection" name="ServTypeSelection" method="post" > <input type="checkbox" name = "$row_ServType['TypeName']" id="$row_ServType['TypeName']" value="$row_ServType['TypeName']"/>
                  <input name="SubmitServList" type="hidden" id="SubmitServList" value="ListingForm" />
                  </form></td>
                  <td><?php echo $row_ServType['TypeName']; ?></td>
                </tr>
                <?php } while ($row_ServType = mysql_fetch_assoc($ServType)); ?>
            </table>
            <p> </p>
          </div>
          <center><input name="ListingSave" type="submit" id="ListingSave" value="Save" /></center></td>
        </tr> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.