Xtremer360 Posted March 6, 2011 Share Posted March 6, 2011 I echoed the query once and it came up as UPDATE `fields` SET `enabled` = 'True' WHERE `ID` = ''good Not sure why. <?php // Include the database page include ('../inc/dbconfig.php'); $styleID = $_GET['id']; $query = "SELECT fields.ID, fields.fullName, fields.enabled FROM fields INNER JOIN styles ON styles.ID = fields.styleID WHERE styles.ID = '" . $styleID . "'"; $result = mysqli_query ( $dbc, $query ); // Run The Query ?> <script> $(document).ready(function() { $('div.message-error').hide(); $('div.message-success').hide(); $("#bioConfigForm").submit(function() { $('div.message-error').hide(); var data = $(this).serialize() + "&submitBioFields=True"; $.ajax({ type: "POST", url: "processes/bioconfig.php", data: data, success: function() { $('div.message-error').hide(); $("div.message-success").html("<h6>Operation successful</h6><p>Bio fields saved successfully.</p>"); $("div.message-success").show().delay(10000).hide("slow", function() { $('#content').load('mods/bioconfiguration.php'); }); } }); return false; }); }); </script> <!-- Title --> <div id="title" class="b2"> <h2>Bio Configuration</h2> <!-- TitleActions --> <div id="titleActions"> <!-- ListSearch --> <div class="listSearch actionBlock"> <div class="search"> <label for="search">Recherche</label> <input type="text" name="search" id="search" class="text" /> </div> <div class="submit"> <button type="submit" id="search-button" class="button"><strong><img src="img/icons/search_48.png" alt="comments" class="icon "/></strong></button> </div> </div> <!-- /ListSearch --> </div> <!-- /TitleActions --> </div> <!-- Title --> <!-- Inner Content --> <div id="innerContent"> <!-- Form --> <form action="#" id="bioConfigForm" > <fieldset> <legend>Bio Config</legend> <?php while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { ?> <div class="field"> <label for="<?php '' . $row['ID'] . '' ?>"><?php echo '' . $row['fullName'] . ''?></label> <input type="radio" value="0" name="<?php echo $row['ID']; ?>" class="status" <?php if($row['enabled'] == 0) echo ' checked="checked"'; ?> />Enabled <input type="radio" value="1" name="<?php echo $row['ID']; ?>" class="status" <?php if($row['enabled'] == 1) echo ' checked="checked"'; ?> />Disabled </div> <?php } ?> <input type="submit" class="submit" name="submitBioFields" id="SubmitBioFields" title="Submit Bio Fields" value="Submit Bio Fields"/> </fieldset> </form> <!-- /Form --> <?php // Include the database page require ('../inc/dbconfig.php'); if (isset($_POST['submitBioFields'])) { foreach($_POST as $bioFieldID => $value) { $query = "UPDATE `fields` SET `enabled` = '".$value."' WHERE `ID` = '".$biofieldID."'"; } mysqli_query($dbc,$query); $result = "good"; } else { $result = "bad"; } //Output the result echo $result; ?> Link to comment https://forums.phpfreaks.com/topic/229783-odd-echoed-query/ Share on other sites More sharing options...
Pikachu2000 Posted March 6, 2011 Share Posted March 6, 2011 Have you done a View--->Source to see if the extra character is present in the markup? Link to comment https://forums.phpfreaks.com/topic/229783-odd-echoed-query/#findComment-1183606 Share on other sites More sharing options...
mattal999 Posted March 6, 2011 Share Posted March 6, 2011 You're missing a capital on $biofieldID in the query (Should be $bioFieldID). Link to comment https://forums.phpfreaks.com/topic/229783-odd-echoed-query/#findComment-1183607 Share on other sites More sharing options...
Pikachu2000 Posted March 6, 2011 Share Posted March 6, 2011 Good catch. It looked like just an extra quote to me when I saw it. I guess I should have read the next few lines of code; I might have noticed the echo of the word 'good' after it, lol. Link to comment https://forums.phpfreaks.com/topic/229783-odd-echoed-query/#findComment-1183611 Share on other sites More sharing options...
Xtremer360 Posted March 6, 2011 Author Share Posted March 6, 2011 So I have this now and its putting UPDATE `fields` SET `enabled` = 'True' WHERE `ID` = 'submitBioFields' good for the echoed query. foreach($_POST as $bioFieldID => $value) { $query = "UPDATE `fields` SET `enabled` = '".$value."' WHERE `ID` = '".$bioFieldID."'"; } Link to comment https://forums.phpfreaks.com/topic/229783-odd-echoed-query/#findComment-1183614 Share on other sites More sharing options...
Xtremer360 Posted March 6, 2011 Author Share Posted March 6, 2011 enabled and ID should be equal integers. Link to comment https://forums.phpfreaks.com/topic/229783-odd-echoed-query/#findComment-1183615 Share on other sites More sharing options...
mattal999 Posted March 6, 2011 Share Posted March 6, 2011 Well, if you look at your form, the data being posted will be something like this: Array ( '64' => '1', 'submitBioFields' => 'Submit Bio Fields' ) And then in your code you loop through the array, overwriting your $query each time. This means that the query will use "submitBioFields" as the ID. Personally, I would do this: foreach($_POST as $bioFieldID => $value) { if($bioFieldID != "submitBioFields") { $query = "UPDATE `fields` SET `enabled` = '".$value."' WHERE `ID` = '".$biofieldID."'"; mysqli_query($dbc,$query); } } This would update multiple IDs if necessary, running the query each iteration of the array. Link to comment https://forums.phpfreaks.com/topic/229783-odd-echoed-query/#findComment-1183618 Share on other sites More sharing options...
Xtremer360 Posted March 6, 2011 Author Share Posted March 6, 2011 Close I can tell but something isn't right still because this: if (isset($_POST['submitBioFields'])) { foreach($_POST as $bioFieldID => $value) { if($bioFieldID != "submitBioFields") { $query = "UPDATE `fields` SET `enabled` = '".$value."' WHERE `ID` = '".$biofieldID."'"; mysqli_query($dbc,$query); echo $query; $result = "good"; } } } else { $result = "bad"; } PRODUCES: UPDATE `fields` SET `enabled` = '1' WHERE `ID` = ''UPDATE `fields` SET `enabled` = '1' WHERE `ID` = ''UPDATE `fields` SET `enabled` = '1' WHERE `ID` = ''UPDATE `fields` SET `enabled` = '0' WHERE `ID` = ''UPDATE `fields` SET `enabled` = '0' WHERE `ID` = ''UPDATE `fields` SET `enabled` = '0' WHERE `ID` = ''UPDATE `fields` SET `enabled` = '0' WHERE `ID` = ''UPDATE `fields` SET `enabled` = '0' WHERE `ID` = ''UPDATE `fields` SET `enabled` = '0' WHERE `ID` = ''UPDATE `fields` SET `enabled` = '0' WHERE `ID` = ''UPDATE `fields` SET `enabled` = '0' WHERE `ID` = ''UPDATE `fields` SET `enabled` = '0' WHERE `ID` = ''UPDATE `fields` SET `enabled` = '0' WHERE `ID` = ''UPDATE `fields` SET `enabled` = '0' WHERE `ID` = ''UPDATE `fields` SET `enabled` = '0' WHERE `ID` = ''UPDATE `fields` SET `enabled` = '0' WHERE `ID` = ''UPDATE `fields` SET `enabled` = '0' WHERE `ID` = ''good Link to comment https://forums.phpfreaks.com/topic/229783-odd-echoed-query/#findComment-1183619 Share on other sites More sharing options...
mattal999 Posted March 6, 2011 Share Posted March 6, 2011 Oops, I didn't fix the capital error that I noticed earlier. Fixed code is: if (isset($_POST['submitBioFields'])) { foreach($_POST as $bioFieldID => $value) { if($bioFieldID != "submitBioFields") { $query = "UPDATE `fields` SET `enabled` = '".$value."' WHERE `ID` = '".$bioFieldID."'"; mysqli_query($dbc,$query); echo $query; $result = "good"; } } } else { $result = "bad"; } Nobody is perfect Link to comment https://forums.phpfreaks.com/topic/229783-odd-echoed-query/#findComment-1183620 Share on other sites More sharing options...
Xtremer360 Posted March 6, 2011 Author Share Posted March 6, 2011 FINALLY! And by Finally I mean thank you because I have been at this part for DAYS now. THANK YOU! Link to comment https://forums.phpfreaks.com/topic/229783-odd-echoed-query/#findComment-1183621 Share on other sites More sharing options...
Xtremer360 Posted March 6, 2011 Author Share Posted March 6, 2011 This topic is closed now. Link to comment https://forums.phpfreaks.com/topic/229783-odd-echoed-query/#findComment-1183623 Share on other sites More sharing options...
mattal999 Posted March 6, 2011 Share Posted March 6, 2011 No problem. Glad we could help! Link to comment https://forums.phpfreaks.com/topic/229783-odd-echoed-query/#findComment-1183624 Share on other sites More sharing options...
Pikachu2000 Posted March 6, 2011 Share Posted March 6, 2011 I know you already know this, but you should be validating and sanitizing/casting all form data before using it in a query string. Link to comment https://forums.phpfreaks.com/topic/229783-odd-echoed-query/#findComment-1183625 Share on other sites More sharing options...
Xtremer360 Posted March 6, 2011 Author Share Posted March 6, 2011 Okay I still need to brush up on this topic a little but with this new forum stuff how do you make a topic as being solved? Link to comment https://forums.phpfreaks.com/topic/229783-odd-echoed-query/#findComment-1183628 Share on other sites More sharing options...
Pikachu2000 Posted March 6, 2011 Share Posted March 6, 2011 The Mark Solved button is part of a modification that needs to be reworked since the forums were upgraded . . . Link to comment https://forums.phpfreaks.com/topic/229783-odd-echoed-query/#findComment-1183638 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.