Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New Lounger
    Join Date
    Jul 2014
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Is this JavaScript problem?

    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 Code:
    <td><input type='text' readonly size=15 name='acctno' value='" . $row['acctno'] . "' ></td>
    <
    td><input type='text' readonly size=25 name='bname' value='" . $row['bname'] . "'></td>
    <
    td><input type='text' readonly size=25 name='purpose' value='" . $row['purpose'] . "'></td>
    <
    td><input type='text' size=7 id='paidamt' name='paidamt' value='" . $row['paidamt'] ."'
       
    onblur='calculate_paid(this)'></td>
    <
    td><input type='text' size=7 id='amtdue' name='amtdue' value='" . $row['amtdue'] . "' ></td>
    <
    td><input type='text' size=7 id='prevbal' name='amtdue' value='" . $row['prevbal'] . "' ></td>
    <
    td><input type='text' size=10 id='datepaid' name='datepaid' value='" . $row['datepaid'] . "' ></td>
    <
    td><input type='text' size=3 id='pd' name='pd' value='" . $row['pd'] . "' ></td><br />
    <
    td><input type='submit' name='update' value='Make Payment' />
    </
    tr>";
       }
    echo "
    </table>
    <
    input type='submit' name='update' value='Update Record' />
    </
    form>";
      }
    else{echo "
    invalid entry<br />Select another?<br />";}
      }
    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!"; 
      } 
       ?> 
    HTML Code:
    ]<form method="post" action="#"><br /> 
     <input type="text" name="acctno"/> <p> 
    <input type="submit" name="submit" value="Select"/>
    </form></body></html>
    Last edited by 12Strings; 2014-07-20 at 19:31. Reason: Fixed PHP end code

  2. #2
    Platinum Lounger
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    3,738
    Thanks
    7
    Thanked 241 Times in 229 Posts
    I may have missed the obvious but I can't see where you have described the problem.

    cheers, Paul

  3. #3
    Silver Lounger Banyarola's Avatar
    Join Date
    Dec 2009
    Location
    Big Indian, New York
    Posts
    1,854
    Thanks
    7
    Thanked 63 Times in 52 Posts
    Java Script is not the problem..It's Java that's the problem...There is a difference between the two.
    "If You Are Reading This In English, Thank A VET"

  4. The Following User Says Thank You to Banyarola For This Useful Post:

    12Strings (2014-07-25)

  5. #4
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    10,358
    Thanks
    130
    Thanked 1,162 Times in 1,069 Posts
    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?
    Rui
    -------
    R4

  6. #5
    New Lounger
    Join Date
    Jul 2014
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts
    thanks to all. I have never coded in java as far as I know. Please enlighten me why that is your prognosis

  7. #6
    New Lounger
    Join Date
    Oct 2010
    Location
    Cambridge, UK
    Posts
    6
    Thanks
    0
    Thanked 2 Times in 2 Posts
    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:
    <?php
        /* GENERAL */
        // Write this once and include it on each page which needs to access the DB
        $hostname = "YOUR HOST";
        $database = "YOUR BD";
        $username = "YOUR USERNAME";
        $password = "YOUR PASSWORD";
        try{
            $dbconn = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);
            $dbconn->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

  8. #7
    New Lounger
    Join Date
    Jul 2014
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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 : .
    ================================================== ====================
    <html><head> // 2009
    <script>
    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";}
    }
    </script>
    <script type="text/javascript">
    window.google_analytics_uacct = "UA-256751-2";
    </script>
    <script type="text/javascript">
    window.google_analytics_uacct = "UA-256751-2";
    </script>
    </head><body>
    <?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 "<form action='#' method='post'><b>Rent Payment :<br /><br />
    <table cellspacing=0 cellpadding=0 border=1>
    // headers ************************************************** *
    </tr>";
    while($row = mysql_fetch_assoc($result))
    {
    echo "<tr>
    <td><input type='text' size=25 name='name' value='" . $row['name'] . "'></td>
    <td><input type='text' size=2 name='apt' value='" . $row['apt'] . "' ></td>
    <td><input type='text' size=4 id='amtpaid' name='amtpaid' value='" . $row['amtpaid'] ."'
    onBlur='calculate_paid(this)'></td>
    <td><input type='text' size=4 id='rentdue' name='rentdue' value='" . $row['rentdue'] . "'></td>
    <td><input type='text' size=4 id='prevbal' name='prevbal' value='" . $row['prevbal'] ."'
    onBlur='calculate_paid(this)'></td>
    <td><input type='text' size=4 id='hudpay' name='hudpay' value='" . $row['hudpay'] ."' ></td>
    <td><input type='text' size=4 id='tentpay' name='tentpay' value='" . $row['tentpay'] . "'></td>
    <td><input type='text' size=10 id='datepaid' name='datepaid' value='" . $row['datepaid'] . "'></td>
    <td><input type='text' size=1 id='late' name='late' value='" . $row['late'] . "' ></td>
    <td><input type='text' size=25 name='comments' value='" . $row['comments'] . "'></td>
    <td><input type='text' size=4 name='paidsum' value='" . $row['paidsum'] . "' ></td>
    </tr>";
    }
    echo "</table>
    <input type='submit' name='update' value='Make Payment' />
    </form>";
    }
    else{echo "No listing for apartment $apt.<br />Please select another.<br />";}
    }
    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";
    }
    ?>
    <form method="post" action="#">
    <br />
    <input type="text" name="apt"/> <p>
    <input type="submit" name="submit" value="select apartment"/>
    </form>
    <script type="text/javascript"><!--
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    //-->
    </script>
    <script type="text/javascript"><!--
    try {
    var pageTracker = _gat._getTracker("UA-256751-2");
    pageTracker._trackPageview();
    } catch(err) {}
    //-->
    </script>
    <script type="text/javascript"><!--
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    //-->
    </script>
    <script type="text/javascript"><!--
    try {
    var pageTracker = _gat._getTracker("UA-256751-2");
    pageTracker._trackPageview();
    } catch(err) {}
    //-->
    </script>
    </body></html>
    ================================================== ===============================
    <!DOCTYPE html><html>
    <title>invoice payment </title>
    <head>
    <script type="text/javascript">
    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';}
    }
    </script>
    <script type="text/javascript">
    window.google_analytics_uacct = "UA-256751-2";
    </script>
    <script type="text/javascript">
    window.google_analytics_uacct = "UA-256751-2";
    </script>
    <style>body { width: 960px; margin: 0 auto; }</style>
    </head><body><b>
    <?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 "<center>";echo date('m/d/y');echo "</center>";
    // headers *********************************
    while($row = mysql_fetch_assoc($result))
    {
    echo "<tr><form action='#' method='post'>
    <td><input type='text' readonly size=15 name='acctno' value='" . $row['acctno'] . "' ></td>
    <td><input type='text' readonly size=25 name='bname' value='" . $row['bname'] . "'></td>
    <td><input type='text' readonly size=25 name='purpose' value='" . $row['purpose'] . "'></td>
    <td><input type='text' readonly size=6 name='status' value='" . $row['status'] . "'></td>
    <td><input type='text' size=5 name='checkno' value='" . $row['checkno'] . "'></td>

    <td><input type='text' size=7 id='paidamt' name='paidamt' value='" . $row['paidamt'] ."'
    onBlur='calculate_paid(this)'></td>

    <td><input type='text' size=7 id='amtdue' name='amtdue' value='" . $row['amtdue'] . "'></td>

    <td><input type='text' size=7 id='prevbal' name='prevbal' value='" . $row['prevbal'] ."'
    onBlur='calculate_paid(this)'></td>

    <td><input type='text' size=10 id='datepaid' name='datepaid' value='" . $row['datepaid'] . "'></td>
    <td><input type='text' size=1 id='pd' name='pd' value='" . $row['pd'] . "' ></td>
    </tr>";
    }
    echo "</table>
    <input type='submit' name='update' value='Update Record' />
    </form>";

    }
    else{echo "invalid entry<br />Select another?<br />";}
    }
    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!";
    }
    ?>
    <form method="post" action="#"><br />
    <input type="text" name="acctno"/> <p>
    <input type="submit" name="submit" value="Select"/>

    <script type="text/javascript"><!--
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    //-->
    </script>
    <script type="text/javascript"><!--
    try {
    var pageTracker = _gat._getTracker("UA-256751-2");
    pageTracker._trackPageview();
    } catch(err) {}
    //-->
    </script>
    <script type="text/javascript"><!--
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    //-->
    </script>
    <script type="text/javascript"><!--
    try {
    var pageTracker = _gat._getTracker("UA-256751-2");
    pageTracker._trackPageview();
    } catch(err) {}
    //-->
    </script>
    </body></html>
    =======================================
    <!DOCTYPE><html><head><title>Invoice Payment</title>
    <script type="text/javascript">
    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';}
    }
    </script>
    <!--when the paidamt is keyed in, the current date & paid code are autoinserted-->
    <style>
    .center {
    margin: auto;
    width: 70%;
    background-color: #b0e0e6;
    }
    </style>
    </head><body><b>
    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    // error_reporting(0);
    // define variables and set to empty values
    $acctno=''; $pd='';$payrec='';$bname='';$amtdue=''; $paidamt='';$datepaid='';$prevbal='';
    // CONNECT TO THE DATABASE
    $DB_NAME = 'homedb';$DB_HOST = 'localhost';$DB_USER = 'root';$DB_PASS = 'cookie';
    $mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
    if (mysqli_connect_errno())
    {printf("Connect failed: %s\n", mysqli_connect_error());exit();}
    // QUERY ON "oocust" TABLE
    $query = "SELECT * FROM `oocust` WHERE acctno = '$acctno'";
    $result = $mysqli->query($query) or die($mysqli->error.__LINE__);
    echo date('m/d/y');
    // headers *******************************
    // Associative array
    while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
    {
    echo "<tr>
    <td><input type='text' readonly size=15 name='acctno[]' value='" . $row['acctno'] . "' ></td>
    <td><input type='text' readonly size=25 name='bname[]' value='" . $row['bname'] . "'></td>
    <td><input type='text' readonly size=25 name='purpose[]' value='" . $row['purpose'] . "'></td>
    <td><input type='text' size=7 id='paidamt' name='paidamt[]' value='" . $row['paidamt'] ."'
    onBlur='calculate_paid(this)'></td>
    <td><input type='text' size=7 id='amtdue' name='amtdue[]' value='" . $row['amtdue'] . "'></td>
    <td><input type='text' size=7 id='prevbal' name='prevbal[]' value='" . $row['prevbal'] ."'
    onBlur='calculate_paid(this)'></td>
    <td><input type='text' size=10 id='datepaid' name='datepaid[]' value='" . $row['datepaid'] . "'></td>
    <td><input type='text' size=1 id='pd' name='pd[]' value='" . $row['pd'] . "' ></td>
    <input type='submit' name='update' value='Update Record' />
    </tr>";
    echo "</table>
    </form>";
    }
    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()."<br />\n.$sql);
    else{echo "Success!"<br />";
    }
    ?>
    <form method="post" action="#">
    <br />
    <input type="text" name="acctno"/> <p>
    <input type="submit" name="submit" value="select acct#."/><p>
    </form>
    </body></html>
    Last edited by 12Strings; 2014-07-25 at 13:59.

  9. #8
    New Lounger
    Join Date
    Oct 2010
    Location
    Cambridge, UK
    Posts
    6
    Thanks
    0
    Thanked 2 Times in 2 Posts
    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:

  10. #9
    New Lounger
    Join Date
    Oct 2010
    Location
    Cambridge, UK
    Posts
    6
    Thanks
    0
    Thanked 2 Times in 2 Posts
    This is dom.php ;-)

    PHP Code:
    <?php
        $hostname 
    "YOUR HOST";
        
    $database "YOUR BD";
        
    $username "YOUR USERNAME";
        
    $password "YOUR PASSWORD";
        try{
            
    $dbconn = new PDO("mysql:host=$hostname;dbname=$database"$username$password);
            
    $dbconn->setAttribute(PDO::ATTR_ERRMODEPDO::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";
    and this is dom.html.php:

    HTML Code:
    <!DOCTYPE html>
    <html>
        <head>
            <title>Make an url!</title>
            <meta charset="utf-8" />
            <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"/>
            <link href="//netdna.bootstrapcdn.com/bootswatch/3.1.1/darkly/bootstrap.min.css" rel="stylesheet"/>
            <link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet"/>
        </head>
        <body>
            <nav class="navbar navbar-default" role="navigation">
                <div class="container-fluid">
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <a class="navbar-brand" href="http://drmsite.co.uk">12String</a>
                    </div>
                    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse">
                        <ul class="nav navbar-nav" id="siteLinks">
                            <li class="active">
                                <a href="#">Record Payment</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </nav>
            <div class="container">
                <form class="form-horizontal" role="form" method="post" action="#">
                    <div class="form-group">
                        <label for="acctno" class="col-sm-2 control-label">Account Number</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="acctno" placeholder="Enter account number here">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="submit" class="btn btn-default" name="submit">Select account</button>
                        </div>
                    </div>
                </form>
            </div>
            <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
            <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
        </body>
    </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
    Last edited by annoyingmouse; 2014-07-27 at 03:54. Reason: Bad SQL fixed ;-)

  11. The Following User Says Thank You to annoyingmouse For This Useful Post:

    12Strings (2014-07-27)

  12. #10
    New Lounger
    Join Date
    Jul 2014
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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. ?
    <?php
    // This is dom.php ;-)

    $hostname = "localhost";
    $database = "homedb";
    $username = "root";
    $password = "cookie";
    try{
    $dbconn = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);
    $dbconn->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` = aidamt,
    `amtdue` = :amtdue,
    `prevbal` = revbal,
    `datepaid` = :datepaid,
    `pd` = :
    WHERE
    `acctno` = :acctno
    ");
    $query->execute(array(
    ":acctno" => $_POST['acctno'],
    ":bname" => $_POST["bname"],
    "urpose" => $_POST["purpose"],
    ":status" => $_POST["status"],
    ":checkno" => $_POST["checkno"],
    "aidamt" => $_POST["paidamt"],
    ":amtdue" => $_POST["amtdue"],
    "revbal" => $_POST["prevbal"],
    ":datepaid" => $_POST["datepaid"],
    "d" => $_POST["pd"]

    ));
    }catch(PDOException $e){
    $error = "Error updating payments: ".$e->getMessage();
    }
    }
    }
    include "dom.html.php";
    ?>
    -------------------------------------------------------
    <!DOCTYPE html>
    <!--this is dom.html.php:-->
    <html>
    <head>
    <title>Make an url!</title>
    <meta charset="utf-8" />
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="//netdna.bootstrapcdn.com/bootswatch/3.1.1/darkly/bootstrap.min.css" rel="stylesheet"/>
    <link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet"/>
    </head>
    <body>
    <nav class="navbar navbar-default" role="navigation">
    <div class="container-fluid">
    <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    </button>
    <a class="navbar-brand" href="http://drmsite.co.uk">12String</a>
    </div>
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse">
    <ul class="nav navbar-nav" id="siteLinks">
    <li class="active">
    <a href="#">Record Payment</a>
    </li>
    </ul>
    </div>
    </div>
    </nav>
    <div class="container">
    <form class="form-horizontal" role="form" method="post" action="#">
    <div class="form-group">
    <label for="acctno" class="col-sm-2 control-label">Account Number</label>
    <div class="col-sm-10">
    <input type="text" class="form-control" name="acctno" placeholder="Enter account number here">
    </div>
    </div>
    <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
    <button type="submit" class="btn btn-default" name="submit">Select account</button>
    </div>
    </div>
    </form>
    </div>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
    </body>
    </html>

  13. #11
    New Lounger
    Join Date
    Oct 2010
    Location
    Cambridge, UK
    Posts
    6
    Thanks
    0
    Thanked 2 Times in 2 Posts
    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 Code:
        error_reporting(E_ALL);
        
    ini_set('display_errors''1'); 
    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...?
    Last edited by annoyingmouse; 2014-07-28 at 06:56. Reason: Added p.s.

  14. #12
    New Lounger
    Join Date
    Jul 2014
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts
    ---------------------------------------------------------------
    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;
    ukblkpay.png

    I'm including the form I had when I first posted:
    payment.png


    Just for funsies I saved dom.html.php to dom.html and saw this:
    ukpay.png
    Last edited by 12Strings; 2014-07-28 at 15:40. Reason: correction

  15. #13
    New Lounger
    Join Date
    Oct 2010
    Location
    Cambridge, UK
    Posts
    6
    Thanks
    0
    Thanked 2 Times in 2 Posts
    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!

  16. The Following User Says Thank You to annoyingmouse For This Useful Post:

    12Strings (2014-07-29)

  17. #14
    New Lounger
    Join Date
    Jul 2014
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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.
    ================================================== ==

  18. #15
    New Lounger
    Join Date
    Jul 2014
    Posts
    10
    Thanks
    3
    Thanked 0 Times in 0 Posts
    this is a dropdown menu to select and display one of several email accounts. I haven't got the update working yet

    <!DOCTYPE html><html>
    <meta charset=utf-8>
    <title>invoice payment </title>
    <head>
    </head>
    <BODY>

    <?php
    echo "<center>";echo date('m/d/y');echo "</center>";
    $id="''";
    $con=mysqli_connect("localhost","root","cookie","h omedb");

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

    if(mysqli_errno($con))
    {echo "Can't Connect to mySQL:".mysqli_connect_error();}
    else
    {echo "</br>";}

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

    echo "<select name= 'target'>";
    echo '<option value="">'.'---select email account ---'.'</option>';
    $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 "<option class=highlight value='". $row['target']."'>".$row['target']
    .'</option>';}
    echo '</select>';
    ?>
    <input type="submit" name="submit" value="Submit"/>
    </form>
    <?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 "<br /><br />lastused is now ".$data['lastused'];
    //
    // =============================== this displays the table

    echo '<table border="1">'.'<tr>'.'<td bgcolor="#FFD47F" align="center">'. 'email menu'. '</td>'.'</tr>';
    echo '<tr>'.'<td>'.'<table border="1">'.'<tr>'.'<td bgcolor="#ccffff">'.'target'.'</td>'.'<td bgcolor="#ccffff">'.'username'.'</td>'.'<td bgcolor="#ccffff">'. 'password' .'</td>'.'<td bgcolor="#ccffff">'. 'emailused'. '</td>'.'<td bgcolor="#FFD47F">'. 'lastused' .'</td>'.'<td bgcolor="#ccffff">'. 'purpose'. '</td>'.'<td bgcolor="#ccffff">'. 'saved' .'</td>'.'</tr>';
    while($data = mysqli_fetch_row($fetch))
    // while($data=mysqli_fetch_row($result))
    {echo ("<tr><td>$data[0]</td><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td><td>$data[4]</td><td>$data[5]</td><td>$data[6]</td></tr>");}
    echo '</table>'.'</td>'.'</tr>'.'</table>';
    }
    ?>
    </body></html>
    Last edited by 12Strings; 2014-07-29 at 20:59.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •