Jump to content

Having Problems Updating Form Without Refresh


MIPS64

Recommended Posts

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() + "&notice=" + $('#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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 + "&notice=" + 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.

 

jquery.jpg

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.