Problems recovering serialized form data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vaughtg
Forum Commoner
Posts: 39
Joined: Thu Feb 17, 2011 9:43 am

Problems recovering serialized form data

Post by vaughtg »

hey folks, not exactly a n00b here, but it's been awhile and I've been doing mostly Java for the past several months.

I've got a form submission via AJAX that goes thus

Code: Select all

  function submitEdits(){
    if(validate()){
      var frm = document.forms.frmSchoolHistory;
      var el = document.createElement("input");
      el.type = "hidden";
      el.name = "save";
      el.value = "yes";
      $("[name='frmSchoolHistory']").append(el);
      el = document.createElement("input");
      el.type = "hidden";
      el.name = "q";
      el.value = histID;
      $("[name='frmSchoolHistory']").append(el);
      $.ajax({
        url:"updateSchoolHistory.php",
        data:$("[name='frmSchoolHistory']").serialize(),
        success:(function(data) { alert(data); }),
        fail:(function(data) { alert(data); })
      })
    }
  }
And things are cool - except I'm drawing a complete blank when it comes to getting the data back out on the other end

Code: Select all

<?php session_start();
  require_once '../classes/DBConnection.php';
  require '../classes/Applicant.php';
  $applicant = new Applicant();
  $query .= "select count(*) from ";
  $bindsArray = array();
  $bindsArray[] = $_SESSION["user"];
  if(!isset($_POST['q']) || "0" == $_POST['q']){
    $query .= "MY_TABLE where userid=?";
  }else{
    $query .= "ANOTHER_TABLE where userid=? and histid=?";
    $bindsArray[] = $_POST['q'];
  }
  /*
  $conn = new DBConnection();

  if(0 < $conn->getRowCount($query, $bindsArray)){
    $histId = $applicant->updateSchoolHistory($histId, $_SESSION['user']);
  }
  */
?>
schoolName is <?php echo $_POST['schoolName'];?>
when I run this, I get the alert that says "schoolName is" and nothing else. I'm figuring this is brain-dead simple and I'm just making it too hard, but I cannot figure it out.

Help...? :banghead: :banghead: :banghead:
vaughtg
Forum Commoner
Posts: 39
Joined: Thu Feb 17, 2011 9:43 am

Re: Problems recovering serialized form data

Post by vaughtg »

got it. feelin' a bit sheepish over this.

Code: Select all

<?php session_start();
  require_once '../classes/DBConnection.php';
  require '../classes/Applicant.php';
  $applicant = new Applicant();
  $query .= "select count(*) from ";
  $bindsArray = array();
  $bindsArray[] = $_SESSION["user"];
  if(!isset($_REQUEST['q']) || "0" == $_REQUEST['q']){
    $query .= "MY_TABLE where userid=?";
  }else{
    $query .= "OTHER_TABLE where userid=? and histid=?";
    $bindsArray[] = $_REQUEST['q'];
  }

  $conn = new DBConnection();

  if(0 < $conn->getRowCount($query, $bindsArray)){
    $histId = $applicant->updateSchoolHistory($histId, $_SESSION['user']);
  }

?>
schoolName is <?php echo $_REQUEST['schoolName'];?>
Post Reply