Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,841 members, 7,813,831 topics. Date: Tuesday, 30 April 2024 at 07:25 PM

why the unexpected $end - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / why the unexpected $end (898 Views)

Parse Error: Syntax Error, Unexpected T_else In C:\ / Unexpected $end / Dreamweaver (an Unexpected Error Has Occured) (2) (3) (4)

(1) (Reply) (Go Down)

why the unexpected $end by ckdoublene: 10:51pm On Dec 28, 2010
why do I get this message at the last line of code - can someone help me with this, please ?

<?php
mysql_connect(localhost,root,""wink;
mysql_select_db(test) or die( "Unable to select database"wink;
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"wink {$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."wink;
echo "Records have been updated";
?>
</script></head></html>
Re: why the unexpected $end by Nobody: 2:12am On Dec 29, 2010
Can you attach the whole HTML file plus the JavaScript? And what exactly are you trying to accomplish?
Re: why the unexpected $end by ckdoublene: 2:43am On Dec 29, 2010
I'm accessing a database & changing fields in the input before I update the record when I enter the amtpaid. it correctly inserts the date, tentpay, paidsum & the L when the date is greater than 5 but not the prevbal, secdep, damage, latechg, courtcost or nsf. The trouble is that I don't know where/when to use parseInt & .value .
Re: why the unexpected $end by Nobody: 9:34pm On Dec 30, 2010
let me help u out

in javascript variables are declared with var however a value can have 12 but as a string so if u add that with lets say 14 it will convert the whole values to string giving u 1214 which is concatenating however to convert a string value var value="12" to an actual number u use parseInt it will parse the string and convert it to 12,here's a trick var trick="12bombs" if u parse that it will be converted to 12 and the others will be ignored, so u use parseint if u have a number in a string that u will need to retrieve imgaine i created an app how many wifes do u want to marry, if he inputs 5 wifes there are all strings but since i need only the number i parse the input and retrieve the value hope i helped out, if u still don't grab only me at my mail, could send a pdf file to you.
Re: why the unexpected $end by ckdoublene: 4:19pm On Dec 31, 2010
I have it working now with the below except that if the amtpaid is > totOwed nothing happens?
<script>
function $_(IDS) { return document.getElementById(IDS); }
function calculate_paid() {
   var amtpaid = document.getElementById("amtpaid"wink;
   var rentdue = document.getElementById("rentdue"wink;
var prevbal = document.getElementById("prevbal"wink;
var hudpay = document.getElementById("hudpay"wink;
var tentpay = document.getElementById("tentpay"wink;
var datepaid = document.getElementById("datepaid"wink;
var late = document.getElementById("late"wink;
var damage = document.getElementById("damage"wink;
var courtcost = document.getElementById("courtcost"wink;
var nsf = document.getElementById("nsf"wink;
var latechg = document.getElementById("latechg"wink;
var secdep = document.getElementById("secdep"wink;
  var paidsum = document.getElementById("paidsum"wink;
  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);
// ******************************************************************************
var totOwed = parseInt(rentdue.value) + parseInt(prevbal.value) + parseInt(secdep.value) + parseInt(damage.value) + parseInt(latechg.value) + parseInt(courtcost.value) +
parseInt(nsf.value) - parseInt(hudpay.value);
if(dayNow > 5) { late.value = "L"; totOwed = totOwed.value + 10; }
var excess = parseInt(amtpaid.value - rentdue.value);
if (amtpaid.value >= totOwed) { prevbal.value = totOwed - amtpaid.value ;
excess = 0 ; secdep.value = 0 ; damage.value = 0 ; latechg.value = 0 ;
courtcost.value = 0 ; nsf.value = 0; }
// ******************************************************************************
if (excess < prevbal.value && amtpaid.value > rentdue.value) { prevbal.value = prevbal.value - excess; excess = 0}
if (excess >= prevbal.value) { excess = excess - prevbal.value; prevbal.value = 0 ; }
if (excess < secdep.value && amtpaid.value > rentdue.value) { secdep.value = secdep.value - excess; excess = 0}
if (excess >= secdep.value) { excess = excess - secdep.value; secdep.value = 0 ; }
if (excess < damage.value && amtpaid.value > rentdue.value) { damage.value = damage.value - excess; excess = 0}
if (excess >= damage.value) { excess = excess - damage.value; damage.value = 0 ; }
if (excess < latechg.value && amtpaid.value > rentdue.value) { latechg.value = latechg.value - excess; excess = 0}
if (excess >= latechg.value) { excess = excess - latechg.value; latechg.value = 0 ; }
if (excess < courtcost.value && amtpaid.value > rentdue.value) { courtcost.value = courtcost.value - excess; excess = 0}
if (excess >= courtcost.value) { excess = excess - courtcost.value; courtcost.value = 0 ; }
if (excess < nsf.value && amtpaid.value > rentdue.value) { nsf.value = nsf.value - excess; excess = 0}
if (excess >= nsf.value) { excess = excess - nsf.value; nsf.value = 0 ; }
}
</script>
Re: why the unexpected $end by joefazee(m): 10:00am On Jan 02, 2011
Put } before the last PHP closing tag but your code is not well escaped at $apt = $_POST['apt']; this is injectable, and why are you using the old mysql lib instead of a more faster one like mysqli, or go with a framework like CakePHP/CodeIgniter. learn how to separate presentable layer from logical routines by using template engine like smarty or learn about MVC.

good luck
Re: why the unexpected $end by ckdoublene: 4:40pm On Jan 02, 2011
the below is my new code. I've checked that my database has the rows but nothing happens?
<?php
mysql_connect("localhost","root",""wink;
mysql_select_db("test"wink or die( "Unable to select database"wink;
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"wink {$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
$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'";
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
// mysql_query($sql) or die("Update query failed."wink;
echo "Records have been updated";
}
}
?>
<head></html>
Re: why the unexpected $end by ckdoublene: 8:56pm On Jan 02, 2011
I'm sure that  the problem is that I don't know how to state the variables in the javascript so that it works in the php?
Re: why the unexpected $end by wassolldas: 4:39am On Jan 05, 2011
first thing: Don't ever write code like this! Even when learning, it breeds bad habits. Separate your business logic, user interface and data access codes. Put the JavaScript code in a different file.

Okay,
You have to recognize two things in the following order.

1. PHP code is parsed server side and then ,

2. JavaScript is executed on the client side (in the browser).


Put you JavaScript in a function and use DOM events handler to specify the event that triggers or calls the function.

Document.getElementByID(name) allows you to use the object in the JavaScript code. Use PHP _POST['HTMLelementName']  or _GET to get the form values,
Re: why the unexpected $end by ugdaniels(m): 2:54pm On Jan 06, 2011
You see that error message because you did not close an "if" statement well.

Check your if statement and other loops

especially the

if (condition here)
{
execute
}

If you dont close the curly brackets well, it will give the $end error


Have Phun

Nwachukwu Ugochukwu Daniel

www.buyselltraders.com

(1) (Reply)

Urgent Help Vb 6.0 Program / Geeks Suck At Kissing Bottom / Ten Great Reasons To Learn COBOL

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 33
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.