tags:

views:

25

answers:

2

I'm trying to use form submit with jquery without a page refresh as demonstrated in this tutorial: submite a form without page refresh using jquery demo

It uses the $.ajax function to post the values, which I've included below:

$.ajax({
  type: "POST",
  url: update.php,
  data: dataString, // dataString's value is 'id=5' 
  success: function() { ... };
});

which is working for me in swapping the wrapper that I have around the form...

HOWEVER, when I try to process the dataString in data in update.php (which I'm using to update an entry from a MySQL DB), I get nothing.

in update.php,

I have...

<?php
  require_once('DB.php');
  $dbh = DB:: connect(...);
  if (DB::iserror($dbh)) {
    die(...);
  }
  $aid = isset($_POST['id']);
  // 'id' column datatype is INT
  $sql = "UPDATE [table] SET x = 'blah' WHERE id = ".aid.";";
  $result = $dbh->query($sql);

--regardless, the database doesn't update. Does anyone see a glaring issue that I don't (note: I'm new to jquery and AJAX etc altogether) see? I tried using Safari's developer menu to track what's wrong, but I can't figure out how to track the update.php component. Also, I'm not sure how to apply print_r or var_dump to the variables in the update.php page because I'm posting to it separately from the page that's calling the function in my .js file. Am I approaching this incorrectly? Any assistance would be appreciate--Thanks in advance!

+1  A: 

in your PHP file you write :

$aid = isset($_POST['id']);

instead of (i guess) :

$aid = intval($_POST['id']);
darma
A: 

Got it... you wouldn't have been able to see the problem since I didn't type it here... I've had the tendency to add on a '$' to some of my functions lately -_- However, I did come across "curl" which let's me post to the file directly in the shell environment and see the output that I normally wouldn't be able to see... that was most useful.

Roy