SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need help with code

    this code worked for a long tome but in an effort to modify I got lost and need some direction.below are the error message and the code:
    Parse error: syntax error, unexpected 'calculate_paid' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\invoice\payment.php on line 63
    Code:
    <html><head>
    <!--when the paidamt is keyed in, the current date,& baldue are autoinserted-->
    <script>
    function $_(IDS) { return document.getElementById(IDS); }
    function calculate_paid() {
       var paidamt = document.getElementById("paidamt");
         var amtdue = document.getElementById("amtdue");
     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;
    amtdue.value = parseint(amtdue.value);
    if(amtdue > 0.00) 
    { 
    amtdue.value = parseint(amtdue.value) - parseint(paidamt.value);
    }
    </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
    // error_reporting(0);
    error_reporting(E_ALL ^ E_NOTICE);
    mysql_connect('localhost','root','');
    mysql_select_db('oodb') 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 "<form action='#' method='post'>Invoice Payment :<br /><br />
    <table cellspacing=0 cellpadding=0 border=1>;		
       <tr>		  
    <th>acctno</th>
    <th>Name</th>		  
    <th>Description</th>
    <th>checkno</th>
    <th>Paid Amt</th>		  
    <th>Date Paid</th>
    <th>Amt Due</th> 
       "</tr>	
    while($row = mysql_fetch_assoc($result))
       {
    echo "<tr>
         <td><input type='text' size=25 name='acctno' 'value='" . $row['acctno'] . "'></td>
            <td><input type='text' size=25 name='bname' value='" . $row['bname'] . "'></td>
            <td><input type='text' size=25 name='descr' value='" . $row['descr'] . "'></td>
        <td><input type='text' size=5 name='checkno'  value='" . $row['checkno'] . "'></td>
       <td><input type='text' size=25 id='paidamt' name='paidamt' value='" . 
    $row['paidamt'] ."' 
    onBlur='calculate_paid(this)'></td>	
     <td><input type='text' id='datepaid' size=7 name='datepaid' value='" . 
    $row['datepaid'] . "'></td>
    <td><input type='text' id='amtdue' size=25 name='amtdue' value='" . $row['amtdue'] . "'></td>
       	</tr>";	
        }	
    echo </table>";	
    <input type="submit" name="update" value="Make Payment" />	
    </form>";
        }    		
    else{echo "No listing for account no. $acctno.<br />Please select another.<br />";}
       }
    if(isset($_POST["update"]))
      {	
    $sql = "UPDATE oocust SET	
    datepaid = '" . mysql_real_escape_string($_POST['datepaid']) . "',  
      paidamt = '" . mysql_real_escape_string($_POST['paidamt']) . "',
        amtdue = '" . mysql_real_escape_string($_POST['amtdue']) . "',
        WHERE acctno='".$_POST["acctno"]."'";
    mysql_query($sql) or die("Update query failed: " . mysql_error());
    echo "Record for acct# ".$_POST["acctno"]." has been updated";
    }
    ?>
    <form method="post" action="#">
    <br />
    <input type="text" name="acctno"/> <p>
    <input type="submit" name="submit" value="select acct#."/>
    </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>

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,079
    Mentioned
    53 Post(s)
    Tagged
    0 Thread(s)
    echo </table>"; NEEDS TO BE echo "</table>";

    There was another instance before this somewhere I believe though...

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the input but it didn't change anything

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    This:
    PHP Code:
    echo "<form action='#' method='post'>Invoice Payment :<br /><br />
    <table cellspacing=0 cellpadding=0 border=1>;   <- no
       <tr>          
    <th>acctno</th>
    <th>Name</th>          
    <th>Description</th>
    <th>checkno</th>
    <th>Paid Amt</th>          
    <th>Date Paid</th>
    <th>Amt Due</th> 
       "
    </tr>  // no 
    SB
    PHP Code:
    echo "<form action='#' method='post'>Invoice Payment :<br /><br />
    <table cellspacing=0 cellpadding=0 border=1>        
       <tr>          
    <th>acctno</th>
    <th>Name</th>          
    <th>Description</th>
    <th>checkno</th>
    <th>Paid Amt</th>          
    <th>Date Paid</th>
    <th>Amt Due</th> 
       </tr>"
    ;  // <- this was missing 
    I think ...

  5. #5
    Non-Member
    Join Date
    Oct 2007
    Posts
    363
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Ok, well let's start by making the code easier to read. Your indentation is all over the place, which really doesn't help things.

    So step one is to indent the code to make it at least semi-readable:

    PHP Code:
            <html>
            <head>
                <!--when the paidamt is keyed in, the current date,& baldue are autoinserted-->
                <script>
                function $_(IDS) { return document.getElementById(IDS); }
                function calculate_paid() {
                    var paidamt = document.getElementById("paidamt");
                    var amtdue = document.getElementById("amtdue");
                    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;
                    amtdue.value = parseint(amtdue.value);
                    if(amtdue > 0.00) 
                    { 
                        amtdue.value = parseint(amtdue.value) - parseint(paidamt.value);
                    }
                    </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
            
    // error_reporting(0);
                    
    error_reporting(E_ALL E_NOTICE);
                    
    mysql_connect('localhost','root','');
                    
    mysql_select_db('oodb') 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 
    "<form action='#' method='post'>Invoice Payment :<br /><br />
                            <table cellspacing=0 cellpadding=0 border=1>;        
                            <tr>          
                            <th>acctno</th>
                            <th>Name</th>          
                            <th>Description</th>
                            <th>checkno</th>
                            <th>Paid Amt</th>          
                            <th>Date Paid</th>
                            <th>Amt Due</th> 
                            "
    </tr>    
                            while(
    $row mysql_fetch_assoc($result))
                            {
                                echo 
    "<tr>
                                <td><input type='text' size=25 name='acctno' 'value='" 
    $row['acctno'] . "'></td>
                                <td><input type='text' size=25 name='bname' value='" 
    $row['bname'] . "'></td>
                                <td><input type='text' size=25 name='descr' value='" 
    $row['descr'] . "'></td>
                                <td><input type='text' size=5 name='checkno'  value='" 
    $row['checkno'] . "'></td>
                                <td><input type='text' size=25 id='paidamt' name='paidamt' value='" 

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

                                
    $row['datepaid'] . "'></td>
                                <td><input type='text' id='amtdue' size=25 name='amtdue' value='" 
    $row['amtdue'] . "'></td>
                                </tr>"
    ;    
                            }    
                            echo </
    table>";    
                            <input type="
    submit" name="update" value="Make Payment" />    
                            </form>"
    ;
                        }            
                        else{echo 
    "No listing for account no. $acctno.<br />Please select another.<br />";}
                    }
                    if(isset(
    $_POST["update"]))
                    {    
                        
    $sql "UPDATE oocust SET    
                        datepaid = '" 
    mysql_real_escape_string($_POST['datepaid']) . "',  
                        paidamt = '" 
    mysql_real_escape_string($_POST['paidamt']) . "',
                        amtdue = '" 
    mysql_real_escape_string($_POST['amtdue']) . "',
                        WHERE acctno='"
    .$_POST["acctno"]."'";
                        
    mysql_query($sql) or die("Update query failed: " mysql_error());
                        echo 
    "Record for acct# ".$_POST["acctno"]." has been updated";
                    }
                    
    ?>
                    <form method="post" action="#">
                        <br />
                        <input type="text" name="acctno"/> <p>
                        <input type="submit" name="submit" value="select acct#."/>
                    </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>

  6. #6
    Non-Member
    Join Date
    Oct 2007
    Posts
    363
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Ok, so I've copy pasted this into an editor called "sublime text 2", which gives good colour hinting for php (and many other languages).

    By using this, I was able to spot an error on line 50 (this may be different to your line 50 now, as I've indented the code as you can see above), I can see there is an error because you're writing an "<tr>" outside of " marks in php:

    PHP Code:
        echo "<form action='#' method='post'>Invoice Payment :<br /><br />
                            <table cellspacing=0 cellpadding=0 border=1>;        
                            <tr>          
                            <th>acctno</th>
                            <th>Name</th>          
                            <th>Description</th>
                            <th>checkno</th>
                            <th>Paid Amt</th>          
                            <th>Date Paid</th>
                            <th>Amt Due</th> 
                            "
    </tr>    
    //This should be:

        
    echo "<form action='#' method='post'>Invoice Payment :<br /><br />
                            <table cellspacing=0 cellpadding=0 border=1>;        
                            <tr>          
                                <th>acctno</th>
                                 <th>Name</th>          
                                <th>Description</th>
                                <th>checkno</th>
                                <th>Paid Amt</th>          
                                <th>Date Paid</th>
                                <th>Amt Due</th> 
                            </tr>"

    Notice the colour coding in the screenshot (click the image to enlarge): eIZ9Qlr.png

    Notice the different colour for the </tr> in the above screenshot? That's how I spotted this particular error.

    Also, some other improvements for you: you shouldn't be echoing out html directly from php unless you have a really good reason to do so. It makes your code ugly, hard to read and hard to change. Come out of php and just use plain html, and always indent your code according to the tags to make it easier to read.

    You shouldn't be using the mysql_ functions. You should be using either mysqli (mysql improved) or PDO. PDO is better because it's more secure if you use it properly.

    Also, finally, please read up on mvc and basic mvc frameworks, as they make it easy for you to separate your presentation code (html + css) from your application flow and business logic - you won't get yourself into such a mess as easily if you start using mvc.

    **Edit: Sorry Cups, hadn't spotted your solution above. Clearly we got the same answer

    Hopefully explaining how I spotted the error so easily (take advantage of colour coding in your text editor/ide and always indent your code nicely) should help you.

    One final word of advice - if your text editor or ide supports line numbers, you would easily be able to go to line 50 to work out what was going on. Sometimes the actual error may not be caused by code on exactly line 50, but it will always be around there, or you'll be able to start at that point to at least figure out what's going on.

  7. #7
    Non-Member
    Join Date
    Oct 2007
    Posts
    363
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Here's another screenshot of the same code that also includes the line numbers, so you can see what I meant by that final point in the above post (again, click to enlarge):

    Attachment 61416

  8. #8
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thank you so much for your input. I feel like I'm stuck in a bear trap. I believe this is one of the greatest language I've tried but I can't seem to conquer the syntax. The below
    message after I changed the </tr>
    Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\invoice\payment.php on line 66
    I'm now using notepad++. Man what a utility! It seemed that you had the answer but would you please have another look?


Bookmarks

Posting Permissions

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