Passing multiple variables via ajaxUrl

6 posts by 2 authors in: Forums > CMS Builder
Last Post: October 24, 2017   (RSS)

By Dave - October 16, 2017

Hi Jerry, 

Fort he ajax function, you want to update it to take a second parameter: 

removeSubmission( recordNum, newValue ) {

And for your onclick code you need to quote the values

 onclick="removeSubmission(<?php echo "'$a', '$b'" ?>)">

Which should output something like this: 

 onclick="removeSubmission('123', 'removed')">

And the MySQL code looks good at first glance.

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com

Thanks Dave,

You're burning the midnight oil again I see...

I'll look this over first thing in the morning and let you know how it goes.

Thanks again for being there for us!

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Hi Dave,

I’ve tried to implement your suggested changes. There must be something I don’t understand because the ajax alert pops up, which I assume means that the ajax script is working, and passing something to the remove.php page, there are no errors in the error log, but the database doesn’t get updated.

I’ve tried to simplify the code as much as I can, but can’t get it to work, and I don’t know how to test to see what variables are actually being passed. Could I impose on you to take a look again?

Thanks,

Jerry Kornbluth

Here’s the modified code:

Ajax script:

<script type = "text/javascript">
      function removeSubmission(recNum, newValue ){
    ajaxUrl = "remove.php?submit=1&recNum=" + escape(recNum)+"&newValue=" + escape(newValue);
      
    $.ajax({
    url: ajaxUrl,
    }).done(function() {
        //add code here if anything needs to happen after the ajax call
       alert("Submission Removed");
     });   
      }
  </script>

Set Variables:

  <?php $newValue = "removed" ?>
        <?php $recNum = $upload['num'] ?>

on click call div:

<div id='ajaxlink' onclick="removeSubmission(<?php echo "'$recNum', '$newValue'" ?>)">CLICK TO REMOVE</div>

MySQL script (remove.php)

<?php $newValue = mysql_escape($_REQUEST['newValue']) ?>
<?php mysqlStrictMode(false);  
      $query = "UPDATE `{$TABLE_PREFIX}uploads` SET 
       info5  =  $newValue
                 WHERE num = '".mysql_escape( $_REQUEST['recNum'] )."'"; 
      mysql_query($query) or die("MySQL Error:<br/>\n". htmlspecialchars(mysql_error()) . "\n"); 
      $userNum = mysql_insert_id(); 
      
   ?> 

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Dave - October 24, 2017

Hi Jerry, 

If you're still having troubles with this could you email me details at dave@interactivetools.com and I can take a look.  Cheers!

Dave Edis - Senior Developer
interactivetools.com

Thanks Dave,

I will take you up on your generous offer.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php