MIPS64 Posted October 6, 2012 Share Posted October 6, 2012 I am trying to make my form update without having to refresh it but the data is not being sent to the database. Can you find anything wrong with the jquery? Jquery <script type="text/javascript" src="../includes/jquery-1.8.2.min"></script> <script type="text/javascript"> $(document).ready(function(){ $('#save').click(function(){ var site_name = $("#site_name").val(); var display_notice = $("#display_notice").val(); var notice = $("#notice").val(); $.ajax({ type: "POST", url: "submit_configuration.php", data: "site_name=" + $('#site_name').val() + "&display_notice=" + $('#display_notice').val() + "¬ice=" + $('#notice').val(), cache: false, }); }); }); </script> submit_configuration.php <?php include('../includes/mysql.php'); $site_name = $_POST['site_name']; $display_notice = $_POST['display_notice']; $notice = $_POST['notice']; mysql_query("UPDATE configuration SET site_name = '$site_name', display_notice = '$display_notice', notice = '$notice'"); ?> my form <form id="configuration" name="configuration" method="POST" action="" class="form" /> <table class="data1"> <tr> <td width="50%"> <p style="line-height:20px;"><strong>Site Name</strong></p> <p style="line-height:20px;">The name of the site displayed on the title bar of each page.</p> </td> <td width="50%"><input type="text" id="site_name" name="site_name" maxlength="100" style="width:400px" value="<?php echo $row_configuration['site_name']; ?>" /></td> </tr> <tr> <td width="50%"> <p style="line-height:20px;"><strong>Display Notice</strong></p> <p style="line-height:20px;">Show a notice at the top of each page.</p> </td> <td width="50%"><input type="checkbox" id="display_notice" name="display_notice" value="1" <?php if ($row_configuration['display_notice'] == 1) { echo "checked";} ?> style="border:0"/></td> </tr> <tr> <td width="50%"> <p style="line-height:20px;"><strong>Notice Text</strong></p> <p style="line-height:20px;">The text to show when the Display Notice option is checked.</p> </td> <td width="50%"><input type="text" id="notice" name="notice" maxlength="100" style="width:400px" value="<?php echo $row_configuration['notice']; ?>" /></td> </tr> </table> <br /> <p align="center"><input type="submit" id="save" name="save" value="Save Changes" class="submit" /></p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/269171-having-problems-updating-form-without-refresh/ Share on other sites More sharing options...
Mahngiel Posted October 6, 2012 Share Posted October 6, 2012 There's no reason to wrap it in a ready function since it waits for an event to do anything. But aside from that, what sort of debugging have you done? Are you using any sort of application to monitor the network traffic? Aside from not cleansing any of the incoming user input, the first thing you should do at the dev stage is verifying the data being sent from the script. At the top of the script run a die( print_r($_POST) ); and watch the output. Quote Link to comment https://forums.phpfreaks.com/topic/269171-having-problems-updating-form-without-refresh/#findComment-1383257 Share on other sites More sharing options...
MIPS64 Posted October 6, 2012 Author Share Posted October 6, 2012 I removed the ready function. I removed all my validation for both jquery and PHP because I was trying to troubleshoot and see if anything was conflicting. What type of application do you recommend to monitor network traffic? Quote Link to comment https://forums.phpfreaks.com/topic/269171-having-problems-updating-form-without-refresh/#findComment-1383261 Share on other sites More sharing options...
Mahngiel Posted October 6, 2012 Share Posted October 6, 2012 (edited) i'm a FF fan, so I use firebug. Chrome users have their Dev Tools, and there are a zillion add-ons for whatever you use. Here's an example of POSTed data through AJAX and the response Edited October 6, 2012 by Mahngiel Quote Link to comment https://forums.phpfreaks.com/topic/269171-having-problems-updating-form-without-refresh/#findComment-1383263 Share on other sites More sharing options...
Mahngiel Posted October 6, 2012 Share Posted October 6, 2012 Also, I'm not certain of what you have going on here data: "site_name=" + $('#site_name').val() + "&display_notice=" + $('#display_notice').val() + "¬ice=" + $('#notice').val(), as those are $_GET parameters which forms do not $_POST to. Quote Link to comment https://forums.phpfreaks.com/topic/269171-having-problems-updating-form-without-refresh/#findComment-1383266 Share on other sites More sharing options...
MIPS64 Posted October 6, 2012 Author Share Posted October 6, 2012 Alright, back to the drawing board I guess. Firebug did see the POST being sent but it's my first time working with Jquery so I'll do some more reading and start from scratch. Quote Link to comment https://forums.phpfreaks.com/topic/269171-having-problems-updating-form-without-refresh/#findComment-1383276 Share on other sites More sharing options...
MIPS64 Posted October 6, 2012 Author Share Posted October 6, 2012 I changed my jQuery a little based off of tutorials though I can't seem to get it to the database. <script type="text/javascript" src="../includes/jquery-1.8.2.js"></script> <script type="text/javascript"> $(function() { $("#save").click(function() { var site_name = $("#site_name").val(); var display_notice = $("#display_notice").val(); var notice = $("#notice").val(); $.ajax({ type: "POST", url: "submit_configuration.php", data: "site_name=" + site_name + "&display_notice=" + display_notice + "¬ice=" + notice, }); return false; )}; )}; </script> This is what I get when I put die( print_r($_POST) ); at the top of the page (correct values). Array ( [site_name] => test [display_notice] => 1 [notice] => test [save] => Save Changes ) 1 Firebug showing the POST being made with correct values. Quote Link to comment https://forums.phpfreaks.com/topic/269171-having-problems-updating-form-without-refresh/#findComment-1383300 Share on other sites More sharing options...
MIPS64 Posted October 6, 2012 Author Share Posted October 6, 2012 I believe I have figured it out. Quote Link to comment https://forums.phpfreaks.com/topic/269171-having-problems-updating-form-without-refresh/#findComment-1383365 Share on other sites More sharing options...
Mahngiel Posted October 6, 2012 Share Posted October 6, 2012 Glad to hear it! Let us know if we can help you on your next adventure! Quote Link to comment https://forums.phpfreaks.com/topic/269171-having-problems-updating-form-without-refresh/#findComment-1383381 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.