0

I don't know why I get the message "unexpected $end" at the last line of code - can someone help?

<?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>
3
Contributors
12
Replies
13
Views
6 Years
Discussion Span
Last Post by cossay
1

Make these corrections:
1. On line 2, you wrote

mysql_connect(localhost,root,"");

instead of

mysql_connect("localhost","root","");

2. On line 3, you wrote

mysql_select_db(test) or die( "Unable to select database");

instead of

mysql_select_db("test") or die( "Unable to select database");

3. On line 9, you wrote

if(mysql_num_rows($result))

instead of

if(mysql_num_rows($result))
{

4. On line 32, you wrote

<?php>

instead of

<?php

5. Your query on line 33 to 35 you wrote

$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');

istead of

$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')";

6.Finally, you should add

}
}

after line 38.

After the correction your code should look it this:

<?php
mysql_connect("localhost","root","man");
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";
}
}
?>
0

I mistakenly deleted the last line of your code

<head></html>

You can still add it to the last line.

0

The short message would be: Check your string quoting.

Next, your update query is invalid.
And then, check your javascript, because you mix js and php variables. Not possible like this. Also a } too much I think.

0

If you copied the code that I posted, then the only thing that should result in an error should be on line 2. On that line, you wrote

mysql_connect("localhost","root","");

but I changed it to

mysql_connect("localhost","root","man");

when I was testing so simply reverse it. On the other hand, if you've changed that and you no longer get the error before but cannot get what you expect from you code, then I think you should check your queries and your javascript codes. Mixing php and javascript codes can make it difficult for even you to understand your own code. A better way would be for you to put all you javascript functions in an external file and then call them where appropriate.

0

If your javascript file is in the same folder as your php script, simply add the line in between your head tags like this

<head>
<script language = "javascript" type = "text/javascript" src = "javascript.js"></script>
</head>

Now you can call the functions as if they are embedded in page by their names and passing them the necessary parameters.

0

pritaeas, could you please tell me how I should be stating my variables? That has been my doubt all along. I don't know how to assign values in the javascript to the php

Edited by ckdoublenecks: n/a

0

As you may know Javascript is a client-side scripting whereas PHP is a server-side scripting language. That's they are two different languages and cannot share a variable.

0

As you may know Javascript is a client-side scripting whereas PHP is a server-side scripting language. That's they are two different languages and cannot share a variable.

so the calcs must be done in php?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.