why the unexpected $end

Discussion in 'JavaScript' started by ckdoublenecks, Jan 1, 2011.

  1. #1
    Someone tell me why I get this message "unexpected $end" at the last line of code, please

    <?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";
    ?>
    </head></html>
    Code (markup):
     
    ckdoublenecks, Jan 1, 2011 IP
  2. fr33lanc3

    fr33lanc3 Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You need to add a double quote at the end of your $sql.

    $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')";
     
    fr33lanc3, Jan 1, 2011 IP
  3. ckdoublenecks

    ckdoublenecks Guest

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks for the help. no more error but no update either?
     
    ckdoublenecks, Jan 1, 2011 IP
  4. ckdoublenecks

    ckdoublenecks Guest

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks for the help, no more error but no update either
     
    ckdoublenecks, Jan 1, 2011 IP
  5. fr33lanc3

    fr33lanc3 Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Are you getting your die message "Update query failed", or just no update?

    Either way, try changing this to output and debug.

    change:
    mysql_query($sql) or die("Update query failed.");

    to:
    echo $qry; // so you can see if the data you expect to be update is being updated.
    mysql_query($sql);
    if ($err = mysql_error()) echo $err; // show query error

    If everything looks ok, my next step would be to go to phpmyadmin and run a query with the criteria you are trying to match on to see if any rows are found.
    Something like select * from payments WHERE prevbal + rentdue = amtpaid OR late = 'L'
    The data may not have any matching rows.
     
    fr33lanc3, Jan 2, 2011 IP
  6. ckdoublenecks

    ckdoublenecks Guest

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I checked the database and I do have have the rows. I changed the code as you suggested but the result is still nada. Someone said I was mixing variables and that was the cause?
     
    ckdoublenecks, Jan 2, 2011 IP
  7. fr33lanc3

    fr33lanc3 Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Your query doesnt have any variables in it.

    What exactly are you wanting to update in the query?
     
    fr33lanc3, Jan 2, 2011 IP
  8. ckdoublenecks

    ckdoublenecks Guest

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    amtpaid = '0', prevbal, tentpay = '0', datepaid = ' ', late = ' ', damage, courtcost, nsf, latechg, secdep, comments = ' ', paidsum = '0'
    WHERE prevbal + rentdue = amtpaid OR late = 'L';
     
    ckdoublenecks, Jan 2, 2011 IP
  9. fr33lanc3

    fr33lanc3 Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I got that much : )

    I was more looking for a verbal explanation than see a query.

    With the query as is, I dont see any conditions to be met based on variables. All fields will be reset to empty/0 on all records where prevbal + rentdue = amtpaid OR late = 'L'

    It is looking at the database field amtpaid, not a variable value amtpaid.
     
    fr33lanc3, Jan 2, 2011 IP
  10. ckdoublenecks

    ckdoublenecks Guest

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I'm sorry, I'm really a novice here. I want to clear the fields in the database record depending on the value of the amtpaid field in the database record. I'm sure you're right but I don't know how to assign values in the javascript to the php? There's nothing in my references this advanced.
     
    Last edited: Jan 2, 2011
    ckdoublenecks, Jan 2, 2011 IP