Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    60
    Thanks
    4
    Thanked 0 Times in 0 Posts

    why do I get the message "unexpected $end"?

    I'm sorry but I'm still learning and don't understand why the message "unexpected $end" pointing to my last code line?

    Code:
    <?php
    mysql_connect(localhost,root,"");
    mysql_select_db(test) 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))
    ?>
    <html><head><script type="text/javascript">
    if ($late = "L") {$rentdue = $rentdue + 10;}
    var excess = $amtpaid - $rentdue;
    var totOwed = $rentdue + $prevbal + $secdep + $damage + $latechg + $courtcost + 
    $nsf - $hudpay;
    if ($amtpaid >= totOwed) { $prevbal = totOwed - $amtpaid; 
    excess = 0 ; $secdep = 0 ; $damage = 0 ; $latechg = 0 ; $courtcost = 0 ; $nsf = 0; }
    if (excess < $prevbal && $amtpaid > $rentdue) { $prevbal = $prevbal - excess; excess = 0}
    if (excess >= $prevbal) { excess = excess - $prevbal; $prevbal = 0 ; }
    if (excess < $secdep && $amtpaid > $rentdue) { $secdep = $secdep - excess; excess = 0}
    if (excess >= $secdep) { excess = excess - $secdep; $secdep = 0 ; }
    if (excess < $damage && $amtpaid > $rentdue) { $damage = $damage - excess; excess = 0}
    if (excess >= $damage) { excess = excess - $damage; $damage = 0 ; }
    if (excess < $latechg && $amtpaid > $rentdue) { $latechg = $latechg - excess; excess = 0}
    if (excess >= $latechg) { excess = excess - $latechg; $latechg = 0 ; }
    if (excess < $courtcost && $amtpaid > $rentdue) { $courtcost = $courtcost - excess; excess = 0}
    if (excess >= $courtcost) { excess = excess - $courtcost; $courtcost = 0 ; }
    if (excess < $nsf && $amtpaid > $rentdue) { $nsf = $nsf - excess; excess = 0}
    if (excess >= $nsf) { excess = excess - $nsf; $nsf = 0 ; }
    }
    </script>
    <?php>
    $sql = "UPDATE payments SET
     amtpaid = '0',  prevbal, tentpay = '0', datepaid = ' ', late = ' ', damage, courtcost, nsf, latechg, secdep, comments = ' ', paidsum = '0' 
    WHERE prevbal + rentdue = amtpaid OR late = 'L');
    mysql_query($sql) or die("Update query failed.");
    echo "Records have been updated";
    ?>
    </script></head></html>

  • #2
    Regular Coder Nile's Avatar
    Join Date
    Jun 2008
    Posts
    280
    Thanks
    2
    Thanked 46 Times in 46 Posts
    Code:
    <?php
    mysql_connect(localhost,root,"");
    mysql_select_db(test) 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))
    ?>
    <html><head><script type="text/javascript">
    if ($late = "L") {$rentdue = $rentdue + 10;}
    var excess = $amtpaid - $rentdue;
    var totOwed = $rentdue + $prevbal + $secdep + $damage + $latechg + $courtcost + 
    $nsf - $hudpay;
    if ($amtpaid >= totOwed) { $prevbal = totOwed - $amtpaid; 
    excess = 0 ; $secdep = 0 ; $damage = 0 ; $latechg = 0 ; $courtcost = 0 ; $nsf = 0; }
    if (excess < $prevbal && $amtpaid > $rentdue) { $prevbal = $prevbal - excess; excess = 0}
    if (excess >= $prevbal) { excess = excess - $prevbal; $prevbal = 0 ; }
    if (excess < $secdep && $amtpaid > $rentdue) { $secdep = $secdep - excess; excess = 0}
    if (excess >= $secdep) { excess = excess - $secdep; $secdep = 0 ; }
    if (excess < $damage && $amtpaid > $rentdue) { $damage = $damage - excess; excess = 0}
    if (excess >= $damage) { excess = excess - $damage; $damage = 0 ; }
    if (excess < $latechg && $amtpaid > $rentdue) { $latechg = $latechg - excess; excess = 0}
    if (excess >= $latechg) { excess = excess - $latechg; $latechg = 0 ; }
    if (excess < $courtcost && $amtpaid > $rentdue) { $courtcost = $courtcost - excess; excess = 0}
    if (excess >= $courtcost) { excess = excess - $courtcost; $courtcost = 0 ; }
    if (excess < $nsf && $amtpaid > $rentdue) { $nsf = $nsf - excess; excess = 0}
    if (excess >= $nsf) { excess = excess - $nsf; $nsf = 0 ; }
    </script>
    <?php
    $sql = "UPDATE payments SET
     amtpaid = '0',  prevbal, tentpay = '0', datepaid = ' ', late = ' ', damage, courtcost, nsf, latechg, secdep, comments = ' ', paidsum = '0' 
    WHERE prevbal + rentdue = amtpaid OR late = 'L'");
    mysql_query($sql) or die("Update query failed.");
    echo "Records have been updated";
    }
    ?>
    </script></head></html>

  • #3
    New Coder
    Join Date
    Jun 2010
    Posts
    60
    Thanks
    4
    Thanked 0 Times in 0 Posts
    thanks for the help. You were right but the " was in the wrong place. Now no error but no update either?

  • #4
    Regular Coder Nile's Avatar
    Join Date
    Jun 2008
    Posts
    280
    Thanks
    2
    Thanked 46 Times in 46 Posts
    Try fixing:
    Code:
    mysql_connect("localhost","root","");
    mysql_select_db("test") or die( "Unable to select database");
    But I dont know, if you're not actually getting an error and the above doesn't work, post in the mysql forum

  • #5
    New Coder
    Join Date
    Jun 2010
    Posts
    60
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I fixed the error by adding a " to OR late = 'L')";. the code is now

    PHP Code:
    <?php
    mysql_connect
    ("localhost","root","");
    mysql_select_db("test") 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))
     {
    ?>
    Code:
    <html><head><script type="text/javascript">
    if ($late = "L") {$rentdue = $rentdue + 10;}
    var excess = $paidsum - $rentdue;
    var totOwed = $rentdue + $prevbal + $secdep + $damage + $latechg + $courtcost + 
    $nsf - $hudpay;
    if ($paidsum >= totOwed) { $prevbal = totOwed - $paidsum; 
    excess = 0 ; $secdep = 0 ; $damage = 0 ; $latechg = 0 ; $courtcost = 0 ; $nsf = 0; }
    if (excess < $prevbal && $paidsum > $rentdue) { $prevbal = $prevbal - excess; excess = 0}
    if (excess >= $prevbal) { excess = excess - $prevbal; $prevbal = 0 ; }
    if (excess < $secdep && $paidsum > $rentdue) { $secdep = $secdep - excess; excess = 0}
    if (excess >= $secdep) { excess = excess - $secdep; $secdep = 0 ; }
    if (excess < $damage && $paidsum > $rentdue) { $damage = $damage - excess; excess = 0}
    if (excess >= $damage) { excess = excess - $damage; $damage = 0 ; }
    if (excess < $latechg && $paidsum > $rentdue) { $latechg = $latechg - excess; excess = 0}
    if (excess >= $latechg) { excess = excess - $latechg; $latechg = 0 ; }
    if (excess < $courtcost && $paidsum > $rentdue) { $courtcost = $courtcost - excess; excess = 0}
    if (excess >= $courtcost) { excess = excess - $courtcost; $courtcost = 0 ; }
    if (excess < $nsf && $paidsum > $rentdue) { $nsf = $nsf - excess; excess = 0}
    if (excess >= $nsf) { excess = excess - $nsf; $nsf = 0 ; }
    }
    </script>
    PHP Code:
    <?php
    $sql 
    "UPDATE payments SET
     amtpaid = '0',  prevbal, tentpay = '0', datepaid = ' ', late = ' ', damage, courtcost, nsf, latechg, secdep, comments = ' ', paidsum = '0' 
    WHERE prevbal + rentdue = paidsum OR late = 'L')"
    ;
    mysql_query($sql) or die("Update query failed.");
    echo 
    "Records have been updated";
    }
    }
    ?>
    Code:
    <head></html>
    it does not update

  • #6
    Regular Coder Nile's Avatar
    Join Date
    Jun 2008
    Posts
    280
    Thanks
    2
    Thanked 46 Times in 46 Posts
    Code:
    <?php 
    $sql = "UPDATE payments SET 
     amtpaid = '0',  prevbal, tentpay = '0', datepaid = ' ', late = ' ', damage, courtcost, nsf, latechg, secdep, comments = ' ', paidsum = '0'  
    WHERE prevbal + rentdue = paidsum OR late = 'L')"; 
    mysql_query($sql) or die("Update query failed."); 
    echo "Records have been updated"; 
    } 
    } 
    ?>
    Get rid of that parenthesis

  • #7
    New Coder
    Join Date
    Jun 2010
    Posts
    60
    Thanks
    4
    Thanked 0 Times in 0 Posts
    My big doubt has always been - how do I state the variables in the javascript so that it works with the php?

  • #8
    Regular Coder Nile's Avatar
    Join Date
    Jun 2008
    Posts
    280
    Thanks
    2
    Thanked 46 Times in 46 Posts
    You need to use ajax for something like that


  •  

    Posting Permissions

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