• Is this JavaScript problem?

    Author
    Topic
    #495640

    Hi guys, my programming is a pasttime but still important to me. The following
    code is a payment doc. allowing partial payments. Balances are put in “prevbal”
    field. Complete payments get a “P” code. When the paidamt is keyed in, the
    current date is autoinserted. If a recurring debt the amtdue stays the same.
    If it is, the amtdue is calculated. I’m unsure if the failure is in the
    javascript or not? The code using the JS follows: The display is right, manual update
    works but not correctly, I get no error & I fear the JS is incorrect but maybe the php
    onblur statement. I’ve worked on this for a long time. I’m not asking for code, pointers maybe?
    ==============================================================================
    :

    Code:
     function $_(IDS) { return document.getElementById(IDS); }
    function calculate_paid()
      {
         var status = document.getElementById(“status”);
                 var pd = document.getElementById(“pd”);
           var payec = document.getElementById(“payec”);   
       var paidamt = document.getElementById(“paidamt”);
         var amtdue = document.getElementById(“amtdue”);
       var prevbal = document.getElementById(“prevbal”);
       var shipamt = document.getElementById(“shipamt”);
     var datepaid = document.getElementById(“datepaid”);
     
      var dateNow = new Date();
      var dayNow = dateNow.getDate();
      var datePaid = (dateNow.getMonth()+1)+”-“+dateNow.getDate()+”-“+dateNow.getFullYear();
    datepaid.value = datePaid;
    var owed.value == parseFloat(amtdue.value) + parseFloat(shipamt.value) +  parseFloat(prevbal.value) – parseFloat(paidamt.value);
    if(status==”N”){amtdue.value = owed.value;}
    if(owed==”0.00″) { pd.value = “P”; shipamt=”0.00″, prevbal=”0.00″;}
      }
    

    ========================================================================

    [PHP]

    “;
    }
    echo “

    “;
    }
    else{echo “invalid entry
    Select another?
    “;}
    }
    if(!empty($_POST[“update”]))
    {
    $sql = “UPDATE oocust SET
    amtdue = ‘” . mysql_real_escape_string($_POST[‘amtdue’]) . “‘,
    paidamt = ‘” . mysql_real_escape_string($_POST[‘paidamt’]) . “‘,
    datepaid = ‘” . mysql_real_escape_string($_POST[‘datepaid’]) . “‘,
    pd = ‘” . mysql_real_escape_string($_POST[‘pd’]) . “‘
    WHERE acctno='”.$_POST[‘acctno’].”‘”;
    mysql_query($sql) or die(mysql_error());
    echo “Success!”;
    }
    ?>
    [/PHP][HTML]]

    [/HTML]

    Viewing 6 reply threads
    Author
    Replies
    • #1460043

      I may have missed the obvious but I can’t see where you have described the problem.

      cheers, Paul

    • #1460151

      Java Script is not the problem..It’s Java that’s the problem…There is a difference between the two.

      • #1460648

        Annoyingmouse, thanks for the response. When I started reading your post
        and saw ‘wee’ I thought “this must be a Brit LOL. I like your handle,
        makes me think of Ratatoulle. I think that along with myself, I have
        some people confused. Before I retired, several years ago, I successfuly
        coded & included this document in a property mgt system. Now with waning
        memory, I’m having trouble recreating it. I found a copy of that code
        (I’m a packrat) and have tried to modify it – it aint working! I hate to
        be verbose but I’m including the 2009 version followed by current “mysql”
        code, which updates the check#, paidamt & auto-inserts the date, then my
        attempt at “mysqli” which doesn’t work : .
        ======================================================================
        // 2009

        function $_(IDS) { return document.getElementById(IDS); }
        function calculate_paid() {
        var amtpaid = document.getElementById(“amtpaid”);
        var rentdue = document.getElementById(“rentdue”);
        var prevbal = document.getElementById(“prevbal”);
        var hudpay = document.getElementById(“hudpay”);
        var tentpay = document.getElementById(“tentpay”);
        var datepaid = document.getElementById(“datepaid”);
        var late = document.getElementById(“late”);
        var paidsum = document.getElementById(“paidsum”);
        var dateNow = new Date();
        var dayNow = dateNow.getDate();
        var datePaid = (dateNow.getMonth()+1)+”/”+dateNow.getDate()+”/”+dateNow.getFullYear();
        datepaid.value = datePaid;
        paidsum.value = parseInt(paidsum.value) + parseInt(amtpaid.value);
        tentpay.value = parseInt(tentpay.value) + parseInt(amtpaid.value) – parseInt(hudpay.value);
        if(dayNow > 5) { late.value = “L”;}
        }

        window.google_analytics_uacct = “UA-256751-2”;

        window.google_analytics_uacct = “UA-256751-2”;

        <?php
        mysql_connect('localhost','root','cookie');
        mysql_select_db('homedb') or die( "Unable to select database");
        if(!empty($_POST["submit"]))
        {
        $apt = $_POST['apt'];
        $query="SELECT * FROM payments Where apt='$apt'";
        $result=mysql_query($query);
        if(mysql_num_rows($result))
        {
        echo "Rent Payment :

        // headers ***************************************************
        “;
        while($row = mysql_fetch_assoc($result))
        {
        echo “

        “;
        }
        echo “

        “;
        }
        else{echo “No listing for apartment $apt.
        Please select another.
        “;}
        }
        if(!empty($_POST[“update”]))
        {
        $sql = “UPDATE payments SET
        name = ‘” . mysql_real_escape_string($_POST[‘name’]) . “‘,
        amtpaid = ‘” . mysql_real_escape_string($_POST[‘amtpaid’]) . “‘,
        rentdue = ‘” . mysql_real_escape_string($_POST[‘rentdue’]) . “‘,
        prevbal = ‘” . mysql_real_escape_string($_POST[‘prevbal’]) . “‘,
        hudpay = ‘” . mysql_real_escape_string($_POST[‘hudpay’]) . “‘,
        tentpay = ‘” . mysql_real_escape_string($_POST[‘tentpay’]) . “‘,
        datepaid = ‘” . mysql_real_escape_string($_POST[‘datepaid’]) . “‘,
        late = ‘” . mysql_real_escape_string($_POST[‘late’]) . “‘,
        comments = ‘” . mysql_real_escape_string($_POST[‘comments’]) . “‘,
        paidsum = ‘” . mysql_real_escape_string($_POST[‘paidsum’]) . “‘
        WHERE apt='”.$_POST[“apt”].”‘”;
        mysql_query($sql) or die(“Update query failed.”);
        echo “Record for apartment “.$_POST[“apt”].” has been updated”;
        }
        ?>

        =================================================================================

        invoice payment

        function $_(IDS) { return document.getElementById(IDS); }
        function calculate_paid()
        {
        var status = document.getElementById(“status”);
        var pd = document.getElementById(“pd”);
        var paidamt = document.getElementById(“paidamt”);
        var amtdue = document.getElementById(“amtdue”);
        var prevbal = document.getElementById(“prevbal”);
        var datepaid = document.getElementById(“datepaid”);
        var dateNow = new Date();
        var dayNow = dateNow.getDate();
        var paydate = (dateNow.getMonth()+1)+”/”+dateNow.getDate()+”/”+dateNow.getFullYear();
        datepaid.value = paydate;

        parseFloat(prevbal.value) = parseFloat(amtdue.value) – parseFloat(paidamt.value);

        if(status.value==’N’){amtdue.value = prevbal.value;prevbal.value==’0.00′;}
        if(amtdue.value==’0.00′ || prevbal.value==’0.00′) {pd.value = ‘P’;}
        }

        window.google_analytics_uacct = “UA-256751-2”;

        window.google_analytics_uacct = “UA-256751-2”;

        body { width: 960px; margin: 0 auto; }

        <?php
        // error_reporting(0);
        error_reporting(E_ALL ^ E_NOTICE);
        mysql_connect('localhost','root','cookie');
        mysql_select_db('homedb') or die("Unable to select database");
        if(!empty($_POST["submit"]))
        {
        $acctno = $_POST['acctno'];
        $query="SELECT * FROM oocust Where acctno='$acctno'";
        $result=mysql_query($query);
        if(mysql_num_rows($result))
        {
        echo "”;echo date(‘m/d/y’);echo “”;
        // headers *********************************
        while($row = mysql_fetch_assoc($result))
        {
        echo “

        “;
        }
        echo “

        “;

        }
        else{echo “invalid entry
        Select another?
        “;}
        }
        if(!empty($_POST[“update”]))
        {
        $sql = “UPDATE oocust SET
        checkno = ‘” . mysql_real_escape_string($_POST[‘checkno’]) . “‘,
        paidamt = ‘” . mysql_real_escape_string($_POST[‘paidamt’]) . “‘,
        amtdue = ‘” . mysql_real_escape_string($_POST[‘amtdue’]) . “‘,
        prevbal = ‘” . mysql_real_escape_string($_POST[‘prevbal’]) . “‘,
        datepaid = ‘” . mysql_real_escape_string($_POST[‘datepaid’]) . “‘,
        pd = ‘” . mysql_real_escape_string($_POST[‘pd’]) . “‘
        WHERE acctno='”.$_POST[‘acctno’].”‘”;
        mysql_query($sql) or die(mysql_error());
        echo “Success!”;
        }
        ?>

        =======================================
        Invoice Payment

        function $_(IDS) { return document.getElementById(IDS); }
        function calculate_paid()
        {
        var status = document.getElementById(“status”);
        var pd = document.getElementById(“pd”);
        var paidamt = document.getElementById(“paidamt”);
        var amtdue = document.getElementById(“amtdue”);
        var prevbal = document.getElementById(“prevbal”);
        var datepaid = document.getElementById(“datepaid”);
        var dateNow = new Date();
        var dayNow = dateNow.getDate();
        var paydate = (dateNow.getMonth()+1)+”/”+dateNow.getDate()+”/”+dateNow.getFullYear();
        datepaid.value = paydate;

        parseFloat(prevbal.value) = parseFloat(amtdue.value) – parseFloat(paidamt.value);

        if(status.value==’N’){amtdue.value = prevbal.value;prevbal.value==’0.00′;}
        if(amtdue.value==’0.00′ || prevbal.value==’0.00′) {pd.value = ‘P’;}
        }

        .center {
        margin: auto;
        width: 70%;
        background-color: #b0e0e6;
        }


        query($query) or die($mysqli->error.__LINE__);
        echo date(‘m/d/y’);
        // headers *******************************
        // Associative array
        while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
        {
        echo “

        “;
        echo “
        “;
        }
        if(!empty($_POST[“update”]))
        {
        $sql = “UPDATE oocust SET
        paidamt = ‘” . mysql_real_escape_string($_POST[‘paidamt’]) . “‘,
        amtdue = ‘” . mysql_real_escape_string($_POST[‘amtdue’]) . “‘,
        prevbal = ‘” . mysql_real_escape_string($_POST[‘prevbal’]) . “‘,
        datepaid = ‘” . mysql_real_escape_string($_POST[‘datepaid’]) . “‘,
        pd = ‘” . mysql_real_escape_string($_POST[‘pd’]) . “‘
        WHERE acctno='”.$_POST[“acctno”].”‘”;
        mysql_query($sql) or die(“Update query failed: ” . mysql_error().”
        n.$sql);
        else{echo “Success!”
        “;
        }
        ?>

        • #1460828

          WOW 12Strings, no wonder I was getting confused… one document with PHP, HTML, JavaScript, SQL and the odd bit of CSS all mixed up? I code a lot with JavaScript and PHP and I still end up putting var in my PHP… also, there must be a special hell for people who make coders look at old code – I look at things that I coded 6 months ago and feel slightly poorly!

          Your 2nd version looks like it won’t work – I’ve copied and pasted it and it seems as though it’s incorrectly nested… probably down to the mixture of languages 😉 For instance – your table and form don’t get started for the rows!

          Over the course of the years I’ve been at this I’ve clocked the value of splitting things down. I think I mentioned this in my original reply but write your whatever code within a PHP file then get it to var_dump what you want at the bottom of the script as basic text… then write your html… then your JavaScript… does that make sense. Bear with and I’ll have a crack:

    • #1460167

      I don’t develop in PHP, so I am not even aware of the available tools, but can you debug and verify the values you are receiving before writing them to the database?
      Have you tried debugging the javascript in a browser, to check if the values are being properly calculated?

      • #1460300

        thanks to all. I have never coded in java as far as I know. Please enlighten me why that is your prognosis

    • #1460516

      Hi there,

      I’ve had a look and I’m a wee bit confused as there’s something of a mixture of languages at play. Looks like you’ve got PHP generating HTML and then interacting with JavaScript in order to do stuff? Is that the case?

      It might be worth looking at creating an index.php page where your logic is created and then an order.html.php (included in your index.php like this: include “order.html.php”;) where your data is displayed. You can have your index form accept post and update your database if it detects the if(isset($_POST[“submit”])){} // process form and then display error/success messages using the same order.html.php.

      I’m more than happy to help but I’d perhaps need to see the page in action first. Might I also suggest that you use the lovely jQuery JavaScript library as it makes accessing things in the DOM a breeze?

      Another suggestion is to use the PHP PDO class – makes your SQL ever so nice to look at:

      Code:
      setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
              $dbconn->exec(‘SET NAMES “utf8″‘);
          }catch (PDOException $e){
              $error = “Unable to connect to the database server.”;
              // Display error to user
              exit();
          }
          /* SPECIFIC */
          try{
              $query = $dbconn->prepare(”
                  UPDATE 
                      oocust 
                  SET  
                      amtdue = :amtdue,
                      paidamt = :paidamt, 
                      datepaid = :datepaid, 
                      pd = :pd
                  WHERE 
                      acctno = :acctno
              “);
              $query->execute(array(
                  “:amtdue” => $_POST[‘amtdue’],
                  “:paidamt” => $_POST[“paidamt”],
                  “:datepaid” => $_POST[“datepaid”],
                  “:pd” => $_POST[“pd”], 
                  “:acctno” => $_POST[“acctno”]
              ));        
          }catch(PDOException $e){
              $error = “Error retrieving user: “.$e->getMessage();
              // Display error to user
              exit();
          }

      JavaScript is a top language! But can be misused 🙁

      Let me know if I can help.

      Dom

    • #1460830

      This is dom.php 😉

      [PHP]setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $dbconn->exec(‘SET NAMES “utf8″‘);
      }catch (PDOException $e){
      $error = “Unable to connect to the database server.”;
      }
      if(!empty($_POST[“submit”])){ // Should perhaps check to see if $_POST[‘apt’] exists in the first place…?
      try{
      $query = $dbconn->prepare(”
      SELECT
      *
      FROM
      `payments`
      WHERE
      `apt` = :apt
      “);
      $query->execute(array(
      “:apt” => $_POST[‘apt’]
      ));
      if($query->rowCount() > 0){
      $lines = array();
      while($row = $query->fetch()){
      $lines[] = array(
      “acctno” => $row[“acctno”],
      “bname” => $row[“bname”],
      “purpose” => $row[“purpose”],
      “paidamt” => $row[“paidamt”],
      “amtdue” => $row[“amtdue”],
      “prevbal” => $row[“prevbal”],
      “datepaid” => $row[“datepaid”],
      “pd” => $row[“pd”]
      );
      }
      }else{
      $error = “No listing for apartment!”;
      }
      // JUST TO CHECK:
      var_dump($lines);
      }catch(PDOException $e){
      $error = “Error retrieving payments: “.$e->getMessage();
      }
      }else{
      if(!empty($_POST[“update”])){
      try{
      $query = $dbconn->prepare(”
      UPDATE
      `payments`
      SET
      `name` = :name,
      `amtpaid` = :amtpaid,
      `rentdue` = :rentdue,
      `prevbal` = :prevbal,
      `hudpay` = :hudpay,
      `tentpay` = :tentpay,
      `datepaid` = :datepaid,
      `late` = :late,
      `comments` = :comments,
      `paidsum` = :paidsum
      WHERE
      `apt` = :apt
      “);
      $query->execute(array(
      “:name” => $_POST[“name”],
      “:amtpaid” => $_POST[“amtpaid”],
      “:rentdue” => $_POST[“rentdue”],
      “:prevbal” => $_POST[“prevbal”],
      “:hudpay” => $_POST[“hudpay”],
      “:tentpay” => $_POST[“tentpay”],
      “:datepaid” => $_POST[“datepaid”],
      “:late” => $_POST[“late”],
      “:comments” => $_POST[“comments”],
      “:paidsum” => $_POST[“paidsum”],
      “:apt” => $_POST[‘apt’]
      ));
      }catch(PDOException $e){
      $error = “Error updating payments: “.$e->getMessage();
      }
      }
      }
      include “dom.html.php”;[/PHP]

      and this is dom.html.php:

      [HTML]

      Make an url!

      [/HTML]

      Give that a try… and then we’ll get onto the JavaScript 😉

      Don’t forget the var_dump, see if what you’re getting back is what you’re expecting!

      Take care,

      Dom

      • #1460993

        Thanks for your input, the code seems remarkably clean. I’ve hesitated for too
        long updating to newer options. I can’t say that I fully understand it yet but
        it will come. I modified code only to fit my environment. Currently I’m stuck
        and only can input the account#, after that — there is no after that LOL. I
        agree regarding building code and I’d be better off starting from scratch. I
        need to learn debugging issues. I have, downloaded, script debuggers but the
        documentation leaves me scratching my head. below is current code. ?
        setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $dbconn->exec(‘SET NAMES “utf8″‘);
        }catch (PDOException $e){
        $error = “Unable to connect to the database server.”;
        }
        if(!empty($_POST[“submit”])){ // Should perhaps check to see if $_POST[‘acctno’] exists in the first place…?
        try{
        $query = $dbconn->prepare(”
        SELECT
        *
        FROM
        `oocust`
        WHERE
        `acctno` = :acctno
        “);
        $query->execute(array(
        “:acctno” => $_POST[‘acctno’]
        ));
        if($query->rowCount() > 0){
        $lines = array();
        while($row = $query->fetch()){
        $lines[] = array(
        “acctno” => $row[“acctno”],
        “bname” => $row[“bname”],
        “purpose” => $row[“purpose”],
        “status” => $row[“status”],
        “checkno” => $row[“checkno”],
        “paidamt” => $row[“paidamt”],
        “amtdue” => $row[“amtdue”],
        “prevbal” => $row[“prevbal”],
        “datepaid” => $row[“datepaid”],
        “pd” => $row[“pd”]
        );
        }
        }else{
        $error = “invalid entry”;
        }
        // JUST TO CHECK:
        var_dump($lines);
        }catch(PDOException $e){
        $error = “Error retrieving oocust: “.$e->getMessage();
        }
        }else{
        if(!empty($_POST[“update”])){
        try{
        $query = $dbconn->prepare(”
        UPDATE
        `oocust`
        SET
        `checkno` = :checkno,
        `paidamt` = :paidamt,
        `amtdue` = :amtdue,
        `prevbal` = :prevbal,
        `datepaid` = :datepaid,
        `pd` = :
        WHERE
        `acctno` = :acctno
        “);
        $query->execute(array(
        “:acctno” => $_POST[‘acctno’],
        “:bname” => $_POST[“bname”],
        “:purpose” => $_POST[“purpose”],
        “:status” => $_POST[“status”],
        “:checkno” => $_POST[“checkno”],
        “:paidamt” => $_POST[“paidamt”],
        “:amtdue” => $_POST[“amtdue”],
        “:prevbal” => $_POST[“prevbal”],
        “:datepaid” => $_POST[“datepaid”],
        “:pd” => $_POST[“pd”]

        ));
        }catch(PDOException $e){
        $error = “Error updating payments: “.$e->getMessage();
        }
        }
        }
        include “dom.html.php”;
        ?>
        ——————————————————-

        Make an url!

        • #1461031

          Hey 12Strings – where is this being hosted? If it’s a local machine you could zip up the whole code base and db and I can have a crack at it – if it’s not you maybe want to grant me access and then revoke it when I’ve finished looking? I’m doing this nigh on 12 hours a day at the minute so I’m used to playing within this sphere – I prefer nodejs but this is nice because it’s comfortable and something I can do with my eyes closed (as long as I’ve access to my list of handy functions 😉 )

          From what you’ve said you’re not getting anything through after entering the account# – that’s cool and to be expected but when the page refreshes there should be the output from the SQL query…? Is there really nothing? I was going to alter the dom.html.php to display a table once we knew we were getting some results out of the query…

          Another fun thing to do is add these lines to the top of the dom.php script:

          [PHP] error_reporting(E_ALL);
          ini_set(‘display_errors’, ‘1’);[/PHP]

          That’ll hopefully tell us if I/we’ve done something really silly 😉

          If you get back to me and we know what we’re dealing with then we can work at altering the dom.html.php to display the results.

          Just a though but are you expecting just one or is there likely to be more than one result from the query? I’m only asking because of the use of a table to display the data – if the table was used to sort out the positioning on the page then that’s all gravy! If there’s likely to be more than one then we’re looking at something that might benefit from nice AJAX – I LOVE AJAX!

          I’m thinking that it’s likely to be just one result though – in which case a lot of the logic you’re passing to the JavaScript should perhaps be moved to the PHP as some (most – but not all) users disable JavaScript…

          Anyway, let me know how you get on – I’m about to dive into the joys of the AWS SKD for PHP (it’s actually lovely!). When you get some time have a look at composer – it’s lovely!

          Hope that that helps.

          Dom

          p.s. Just as a though – could you write a query that’ll populate a list of account#s – users a great at adding silly things to search for and while PDO is brilliant at avoiding SQL injection attacks – it might be nice to help them out with limiting what they can enter…?

          • #1461626

            this is a dropdown menu to select and display one of several email accounts. I haven’t got the update working yet

            invoice payment

            <?php
            echo "”;echo date(‘m/d/y’);echo “”;
            $id=”””;
            $con=mysqli_connect(“localhost”,”root”,”cookie”,”homedb”);

            // ============== check connection

            if(mysqli_errno($con))
            {echo “Can’t Connect to mySQL:”.mysqli_connect_error();}
            else
            {echo ““;}

            // ==========This creates the drop down box using records in the table

            echo “”;
            echo ”.’—select email account —‘.”;
            $query = mysqli_query($con,”SELECT target, username, password, emailused, lastused, purpose, saved FROM emailtbl”);
            $query_display = mysqli_query($con,”SELECT * FROM emailtbl”);
            while($row=mysqli_fetch_array($query))
            { echo “”.$row[‘target’]
            .”;}
            echo ”;
            ?>

            <?php
            if(isset($_POST['target']))
            {
            //
            if(!empty($_POST["submit"]))
            { $lastused = $_POST['lastused']; }
            mysql_query("UPDATE emailtbl SET lastused = NOW() WHERE id ='$id'");
            $result=mysql_query("select lastused from emailtbl") or die ("Error – could not retrieve receipt# number from database");
            $data=mysql_fetch_assoc($result);
            echo "

            lastused is now “.$data[‘lastused’];
            //
            // =============================== this displays the table

            echo ‘

            ‘.’

            ‘.’

            ‘.’

            ‘;
            echo ‘

            ‘.’

            ‘.’

            ‘.’

            ‘. ’email menu’. ‘
            ‘.’

            ‘.’

            ‘.’

            ‘.’

            ‘.’

            ‘.’

            ‘.’

            ‘.’

            ‘.’

            ‘.’

            ‘;
            while($data = mysqli_fetch_row($fetch))
            // while($data=mysqli_fetch_row($result))
            {echo (“

            “);}
            echo ‘

            ‘.’target’.’ ‘.’username’.’ ‘. ‘password’ .’ ‘. ’emailused’. ‘ ‘. ‘lastused’ .’ ‘. ‘purpose’. ‘ ‘. ‘saved’ .’
            $data[0] $data[1] $data[2] $data[3] $data[4] $data[5] $data[6]

            ‘.’

            ‘;
            }
            ?>

    • #1461110

      —————————————————————
      no duplicates, have only used AJAX to clean the toilet(don’t know how to spell “lew).
      the files are local.

      When I opened dom.html.php I get this;
      37528-ukblkpay

      I’m including the form I had when I first posted:
      37529-payment

      Just for funsies I saved dom.html.php to dom.html and saw this:
      37530-ukpay

      • #1461607

        Aye, that’s grand! The 1st one that is! You need to enter an account# number and then press enter… what is displayed when you do that? Anything? What should happen is that the underlying PHP should pick up the account# and query the MySQL DB with that account# – which will then be displayed at the top of the page (using the var_dump)… it might not show so if that’s the case have a look at the source of the page (looks like you’re using IE – think you right-click and select view source). If you get the record that you’re expecting then the next step is to display the record and we’ll do that with a simple PHP if within the dom.html.php. That way we can reuse the same page – once for searching for an account# and then again for displaying and editing the account#.

        Does that make sense?

        Cheers,

        Dom

        p.s. Looks like you’re using xampp locally? How cool! Haven’t used that in ages but it’s a fine tool!

        • #1461623

          Aye, that’s grand! The 1st one that is!You need to enter an account# number and then press enter…
          what is displayed when you do that? Anything?
          —————————————————–
          I get a black page with:
          12String (a link to you) – Record Payment(on the same line)
          Account Number – input text box (Enter account number here)
          Select account (submit button)
          no response
          ======================================================
          What should happen is that the underlying PHP should pick up the account#
          and query the MySQL DB with that account# –
          which will then be displayed at the top of the page (using the var_dump)…
          it might not show so if that’s the case have a look at the source of the page
          (looks like you’re using IE –
          think you right-click and select view source).
          —————————————————–
          I must be misunderstanding, I already know the source code.
          ====================================================

    • #1461653

      [PHP]setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      $dbconn->exec(‘SET NAMES “utf8″‘);
      }catch (PDOException $e){
      $error = “Unable to connect to the database server.”;
      }
      if(!empty($_POST[“submit”])){
      try{
      $query = $dbconn->prepare(”
      SELECT
      *
      FROM
      `payments`
      WHERE
      `apt` = :apt
      “);
      $query->execute(array(
      “:apt” => $_POST[‘acctno’]
      ));
      $lines = array();
      if($query->rowCount() > 0){
      while($row = $query->fetch()){
      $lines = array(
      “acctno” => $row[“acctno”],
      “bname” => $row[“bname”],
      “purpose” => $row[“purpose”],
      “paidamt” => $row[“paidamt”],
      “amtdue” => $row[“amtdue”],
      “prevbal” => $row[“prevbal”],
      “datepaid” => $row[“datepaid”],
      “pd” => $row[“pd”]
      );
      }
      }else{
      $error = “No listing for apartment!”;
      }
      }catch(PDOException $e){
      $error = “Error retrieving payments: “.$e->getMessage();
      }
      }else{
      if(!empty($_POST[“update”])){
      try{
      $query = $dbconn->prepare(”
      UPDATE
      `payments`
      SET
      `name` = :name,
      `amtpaid` = :amtpaid,
      `rentdue` = :rentdue,
      `prevbal` = :prevbal,
      `hudpay` = :hudpay,
      `tentpay` = :tentpay,
      `datepaid` = :datepaid,
      `late` = :late,
      `comments` = :comments,
      `paidsum` = :paidsum
      WHERE
      `apt` = :apt
      “);
      $query->execute(array(
      “:name” => $_POST[“name”],
      “:amtpaid” => $_POST[“amtpaid”],
      “:rentdue” => $_POST[“rentdue”],
      “:prevbal” => $_POST[“prevbal”],
      “:hudpay” => $_POST[“hudpay”],
      “:tentpay” => $_POST[“tentpay”],
      “:datepaid” => $_POST[“datepaid”],
      “:late” => $_POST[“late”],
      “:comments” => $_POST[“comments”],
      “:paidsum” => $_POST[“paidsum”],
      “:apt” => $_POST[‘apt’]
      ));
      }catch(PDOException $e){
      $error = “Error updating payments: “.$e->getMessage();
      }
      }
      }
      include “dom.html.php”;[/PHP]

      [HTML]

      12 String

      <input type="text" class="form-control" name="acctno" disabled value="”>

      <input type="text" class="form-control" name="bname" disabled value="”>

      <input type="text" class="form-control" name="purpose" disabled value="”>

      <input type="number" data-original="” class=”form-control” name=”amtdue” value=”” disabled>

      <input type="number" data-original="” class=”form-control” name=”paidamt” value=”” disabled>

      <input type="text" class="form-control" name="pd" value="”>

      $(function(){
      $(“input[name=’pay’]”).on(“change”, function(){
      var $this = $(this);
      var $due = $(“input[name=’amtdue’]”);
      var $payed = $(“input[name=’paidamt’]”);
      var pay = parseInt($this.val(), 10);
      var due = parseInt($due.data(“original”), 10);
      var payed = parseInt($payed.data(“original”), 10);
      $due.val(due – pay);
      $payed.val(payed + pay);
      });
      });

      [/HTML]

      My bad – spun up a server and had a play with the following SQL:

      Code:
      CREATE TABLE IF NOT EXISTS `payments` (
        `acctno` int(11) NOT NULL,
        `bname` varchar(255) NOT NULL,
        `purpose` varchar(255) NOT NULL,
        `paidamt` float NOT NULL,
        `amtdue` float NOT NULL,
        `prevbal` float NOT NULL,
        `datepaid` datetime NOT NULL,
        `pd` int(11) NOT NULL,
        `apt` int(11) NOT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
      
      —
      — Dumping data for table `payments`
      —
      
      INSERT INTO `payments` (`acctno`, `bname`, `purpose`, `paidamt`, `amtdue`, `prevbal`, `datepaid`, `pd`, `apt`) VALUES
      (1, ‘Something here’, ‘Fix the sink’, 10, 100, 110, ‘2014-07-30 11:28:26’, 12, 1);

      Will work on dom.html.php in order to show the data returned from the query now.

      • #1461717

        you mentioned silly, I beg to differ LOL, I spend my time writing docs, such as one to show what city a phone call comes, one I use when I’m performing. I use my laptop instead of sheet music, click on the name and the lyrics & chords are there to see. I have a system for access to
        my email accounts, to modify, list, a dropdown menu that shows the selected file and updates the records date of last used. The menu displays the options in alternate colors.
        Here is the code where all starts It has a fish eye effect, radio buttons
        linking several email providers, browsers & email options: try it out!

        span {font-size: x-large}

        span {font-size: }


        function gotolink() {
        var destination= self.location;

        for(var i = 0; i<document.formname.radiobutton.length; i++){
        if(document.formname.radiobutton.checked) {
        destination=document.formname.radiobutton.value }
        }
        window.location = destination;
        }



        Email Portal


        just having a little


        fun while at the same I’m


        creating a useful shortcut for

        Yahoo
        Bing
        Msn
        Gmail
        Firefox
        Email Options

        users to link to often


        used emails. This is another


        in a never ending wave of


        mlnd boggling intellect

        for

    Viewing 6 reply threads
    Reply To: Is this JavaScript problem?

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: