Dan06 Posted September 25, 2008 Share Posted September 25, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/125850-associative-array-and-post-method-to-update-mysql-table/ Share on other sites More sharing options...
DarkWater Posted September 25, 2008 Share Posted September 25, 2008 I'd be willing to guess that one of the quotes is mismatched or something. Also, inside of the actual query, you need ' ' around all of your values (where you have %s in sprintf()). Quote Link to comment https://forums.phpfreaks.com/topic/125850-associative-array-and-post-method-to-update-mysql-table/#findComment-650772 Share on other sites More sharing options...
Dan06 Posted September 26, 2008 Author Share Posted September 26, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/125850-associative-array-and-post-method-to-update-mysql-table/#findComment-651293 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.