views:

59

answers:

1

Hi I have the following code in my change.php page:

$con = mysql_connect("localhost","root","root");
 if (!$con)
   {
    die('Could not connect: ' . mysql_error());
    }

  mysql_select_db("FACT", $con);


  if($_POST['isChecked']==1)  // SEE THIS LINE PLEASE
  {
  mysql_query("UPDATE Orc SET CON = 'CHECKED'
  WHERE UID = '1'");
   }
  else
   {
   mysql_query("UPDATE Orc SET CON = 'NO'
   WHERE UID = '1'");
   } 

  mysql_close($con);

This page is called from my index.php wich uses jquery and:

  $.post("test.php", { isChecked:$('#checkbox_id').attr('checked') } );

It works almost fine for deslecting the checkbox I still need to manually refresh the page for the change take place in the DB and I cant change the box back to selected...

Im stumped on this one, please help.

Thank you.

A: 

In order to update the page without refreshing you will need to provide a callback function to the ajax call (code to run when the call has been successfully completed). From jQuery Docs:

 $.post("test.php", { name: "John", time: "2pm" },
  function(data){
    alert("Data Loaded: " + data);
  });

So you can use jQueries DOM manipulation to change parts of the page, get the php page to return new data to update the page with, or automatically refresh if you rely on data from the DB.

Adam Heath