Web Analytics Made Easy -
StatCounter help with execute query onload - CodingForum

Announcement

Collapse
No announcement yet.

help with execute query onload

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • help with execute query onload

    Hey All!

    I'm trying to get the following MySQL update to execute from an html document - onload as I might via javascript. The html is a dynamically generated amalgamation of myPage.php and myPage.html smack in the middle of a large php/MySQL based CRM.

    I have tried adding the following at the top of myPage.html:
    PHP Code:
    <?php
    $cycle_update 
    =" UPDATE contacts,emailman set contacts.cycle=contacts.cycle+1 where emailman.related_id = contacts.id and emailman.deleted !=1 "
    $result = @cycle_query ($cycle_query);
    if (
    $result) { $alerts='Contact Cycle Updated';
    } else {
    $message 'Cycle did not update' mysql_error();}
    ?>
    and have also tried adding just the $cycle_update : to various locations within myPage.php, but no luck. I know the sql update itself is correct because I have run it from phpMyAdmin and it executed an updated as expected, just can't seem to get it to execute from within the CRM when and where I need it to. Please. What am I doing wrong here?

  • #2
    Are you getting any errors?
    http://www.hazelryan.co.uk

    Comment


    • #3
      Hi Nancy,
      No, no errors either case.

      Comment


      • #4
        the @ will be suppressing errors, so why put it there before you at least think things work?
        My thoughts on some things: http://codemeetsmusic.com
        And my scrapbook of cool things: http://gjones.tumblr.com

        Comment


        • #5
          Originally posted by GJay View Post
          the @ will be suppressing errors, so why put it there before you at least think things work?
          Well ... because... because I'm a total noob following an a example from "THE BOOK"

          I tried:
          PHP Code:
          <?php
          $cycle_query 
          =" UPDATE contacts,emailman set contacts.cycle=contacts.cycle+1 where emailman.related_id = contacts.id and emailman.deleted !=1 "
          ?>
          but still no luck.

          Comment


          • #6
            That first bit of code you posted you are assigning the query text to a variable $cycle_update but then you pass a variable called $cycle_query to the mysql_query() function. Try passing $cycle_update to mysql_query()?

            Comment


            • #7
              Originally posted by Fumigator View Post
              That first bit of code you posted you are assigning the query text to a variable $cycle_update but then you pass a variable called $cycle_query to the mysql_query() function. Try passing $cycle_update to mysql_query()?
              Dohh!!! Okay that was an obvious oversight! Still, (if I understand correctly) I tried:
              PHP Code:
              <?php 
              $cycle_update 
              =" UPDATE contacts,emailman set contacts.cycle=contacts.cycle+1 where emailman.related_id = contacts.id and emailman.deleted !=1 ";  
              $result = @mysql_query ($cycle_update); 
              if (
              $result) { $alerts='Contact Cycle Updated'; }
              else {
              $message 'Contact Cycles WERE NOT UPDATED' mysql_error();} 
              ?>
              but still no luck

              Comment


              • #8
                Can you be more specific? Does the query work now, but doesn't update what you expect to get updated? Or does the query fail with a SQL error of some kind?

                Comment


                • #9
                  As suggested remove the @.
                  $result = mysql_query ($cycle_update) or die(mysql_error());
                  -Brando
                  Why using tables for eating is stupid!

                  Comment


                  • #10
                    Thanks Fumigator,

                    No errors are returned, but does that necessarily mean that the query "worked" even though no updates were made as a result?

                    Upon clicking my CRM's campaigns.html "Send" button, contacts targeted for a given campaign are added to a queue (emailman), and we are returned to trackcampaign.html (myPage.html) listing the contacts in the queue. The acutal send is scheduled, at which time the queue is truncated.

                    Before the scheduled send was executed (while contacts were queued in emailman) I have opened phpMyAdmin and succesfully run:

                    Code:
                    UPDATE contacts,emailman
                    SET contacts.cycle=contacts.cycle+1'
                    WHERE emailman.related_id = contacts.id'
                    AND emailman.deleted !=1
                    which updates the appropriate contact records, and so is the basis of my $update_cycle query.

                    Why it wouldn't update as written is beyond me.

                    Brando, Gjay,
                    Tried running with:
                    PHP Code:
                    <?php 
                    $cycle_update 
                    =" UPDATE contacts,emailman set contacts.cycle=contacts.cycle+1 where emailman.related_id = contacts.id and emailman.deleted !=1 ";  
                    $result mysql_query ($cycle_update) or die(mysql_error()); 
                    ?>
                    No errors, No Update, No change. I'm beginning to feel REALLY STUPID here.
                    Last edited by fuzzy1; Oct 4, 2006, 12:35 PM.

                    Comment


                    • #11
                      Is that your whole code? E.g are you making a connection to the db first with mysql_connect then selecting a db with mysql_select_db?
                      -Brando
                      Why using tables for eating is stupid!

                      Comment


                      • #12
                        I think the first step is to determine whether or not that snippet of code is even being run.

                        Try getting it to echo out something to screen
                        http://www.hazelryan.co.uk

                        Comment


                        • #13
                          Thanks Again Nancy,
                          I think that brings us back to my original question of how to get it to execute from myPage.html "onload". I added the following:
                          PHP Code:
                          <?php 
                          $cycle_update 
                          =" UPDATE contacts,emailman set contacts.cycle=contacts.cycle+1 where emailman.related_id = contacts.id and emailman.deleted !=1 ";  
                          $result mysql_query ($cycle_update) or die(mysql_error()); 
                          if (
                          $result){echo 'success'; } else { echo 'no joy';}
                          ?>
                          which echos NOTHING

                          Brando: As for the connection to the db, this is in the middle of a php CRM, the db for which, if I understand correctly, I am connected to upon login??
                          Take myPage.php for example (or any other.php in the crm passed login) wherein there is no connect statement of any kind.

                          PHP Code:
                          <?php
                          if(empty($GLOBALS['sugarEntry'])) die('Not A Valid Entry Point');

                          require_once(
                          'XTemplate/xtpl.php');
                          require_once(
                          'data/Tracker.php');
                          require_once(
                          'modules/Campaigns/Campaign.php');
                          require_once(
                          'modules/Campaigns/Forms.php');
                          require_once(
                          'include/DetailView/DetailView.php');
                          require_once(
                          'modules/Campaigns/Charts.php');

                          global 
                          $mod_strings;
                          global 
                          $app_strings;
                          global 
                          $app_list_strings;

                          $focus = new Campaign();

                          $detailView = new DetailView();
                          $offset 0;
                          $offset=0;
                          if (isset(
                          $_REQUEST['offset']) or isset($_REQUEST['record'])) {
                              
                          $result $detailView->processSugarBean("CAMPAIGN"$focus$offset);
                              if(
                          $result == null) {
                                  
                          sugar_die("Error retrieving record.  You may not be authorized to view this record.");
                              }
                              
                          $focus=$result;
                          } else {
                              
                          header("Location: index.php?module=Accounts&action=index");
                          }
                          Last edited by fuzzy1; Oct 4, 2006, 01:33 PM.

                          Comment


                          • #14
                            You cant put PHP in an 'onload' event - it doesnt work like that - the very nature of PHP is that its server side processed - it runs before the page loads.
                            Without knowing where you're trying to put it or anything about your CRM its impossible to say where it should go
                            http://www.hazelryan.co.uk

                            Comment


                            • #15
                              Finally!!!
                              I had to put the query in a function in the module.php
                              then call the function at the end of myPage.php

                              Thanks to all for the input. It did lead to eventual success!

                              Comment

                              Working...
                              X