Please help with DB:Syntax error
Posted: Wed Sep 08, 2010 10:26 pm
Hello,
I am relatively new to PHP, but not to programming. I've recently installed PHP5, MySQL and Apache on a Linux machine. Everything is working great. I came across the book "Beginning PHP4 Databases", put out by Wrox Press. I'm working on a sample application called "Accounts Receivable". The interface works, and I can enter invoices into the database with one of the modules, so that appears to be set up properly. My problem is with most of the modules that pull information from the DB.
I will include one of the shorter modules (Invoice Review Detail) which contains this problem. I think I've pinpointed it to the 3rd "Die" statement in the code. If I comment out that particular line I no longer get the syntax error. Although I then get a "Fatal error: Call to undefined method DB_Error::fetchRow() in /var/www/Accounting/ir.php on line 46" - which is the following line. I'm sure that's a different problem, possibly related to the first. This is in a (fetchRow) statement. If I also comment out that line, the page comes up (but of course with no functionality).
Here's the code. Please let me know what I'm missing; everything looks right to my untrained eyes. (Although I've already found quite a few errors in this sample code; I'm sure there's a logic error that I'm missing):
Thanks in advance!
Brian
bk6662@cox.net
I am relatively new to PHP, but not to programming. I've recently installed PHP5, MySQL and Apache on a Linux machine. Everything is working great. I came across the book "Beginning PHP4 Databases", put out by Wrox Press. I'm working on a sample application called "Accounts Receivable". The interface works, and I can enter invoices into the database with one of the modules, so that appears to be set up properly. My problem is with most of the modules that pull information from the DB.
I will include one of the shorter modules (Invoice Review Detail) which contains this problem. I think I've pinpointed it to the 3rd "Die" statement in the code. If I comment out that particular line I no longer get the syntax error. Although I then get a "Fatal error: Call to undefined method DB_Error::fetchRow() in /var/www/Accounting/ir.php on line 46" - which is the following line. I'm sure that's a different problem, possibly related to the first. This is in a (fetchRow) statement. If I also comment out that line, the page comes up (but of course with no functionality).
Here's the code. Please let me know what I'm missing; everything looks right to my untrained eyes. (Although I've already found quite a few errors in this sample code; I'm sure there's a logic error that I'm missing):
Code: Select all
<?php
require_once("DB.php");
require_once("billing_includes.php");
$db = DB::connect($dsn);
if( DB::isError($db) ) {
die($db->getMessage());
}
if( isset($_GET["invoice_id"]) ) {
$invoice_id = $_GET["invoice_id"];
}
if( isset($_POST["invoice_id"]) ) {
$invoice_id = $_POST["invoice_id"];
}
if( 1 == $_POST["updatepaid"] ) {
$sql = "UPDATE invoices
SET invoice_paid = 1
WHERE invoice_id = " . $invoice_id;
$rs = $db->query($sql);
if( DB::isError($rs) ) {
die ($rs->getMessage());
}
}
// Set up SQL and perform query
$sql = "SELECT i.invoice_id, description_short, description_full,
date_format(date_posted, '%Y-%m-%d') AS date_posted,
date_format(date_due, '%Y-%m-%d') AS date_due
amount_due, invoice_paid, client_firstname,
client_lastname, client_street, client_city,
client_state, client_zip, client_phone
FROM invoices i, clients c, client_invoices ci
WHERE i.invoice_id = $invoice_id
AND ci.invoice_id = $invoice_id
AND c.client_id = ci.client_id";
$rs = $db->query($sql);
if( DB::isError($rs) ) {
[b]// die ($rs->getMessage());[/b]}
[b]$invoice = ($rs->fetchRow (DB_FETCHMODE_ASSOC));[/b]
?>
<html>
<head>
<title=Billing System</title>
<style type="text/css" media="screen">
@import url(billing.css);
</style>
</head>
<body>
<div id="pageheader">
<a href="index.php">Billing System</a> :: Review Invoice
</div><!-- end div pageheader -->
<div id="pagecontent">
<div class="sectionheading">
Invoice ID: <?php echo $invoice["invoice_id"]; ?>
</div>
<table border="0">
<tr>
<td valign="top" class="darker" width="200">Client:</td>
<td class="darker" width="300">
<?php
echo $invoice["client_firstname"] . " " . $invoice["client_lastname"] .
"<br />" . $invoice["client_street"] . "<br />" . $invoice["client_city"] .
", " . $invoice["client_state"] . " " . $invoice["client_zip"] . "<br />" .
$invoice["client_phone"];
?>
</td>
</tr>
<tr>
<td valign="top" class="lighter" width="200">Short Description:</td>
<td class="lighter" width="300"><?php echo
smart_strip_slashes($invoice["description_short"]); ?></td>
</tr>
<tr>
<td valign="top" class="darker" width="200">Full Description:</td>
<td class="darker" width="300"><?php echo
smart_strip_slashes($invoice["description_full"]); ?></td>
</td>
</tr>
<tr>
<td valign="top" class="lighter" width="200">Amount Due:</td>
<td class="lighter" width="300">$<?php echo
number_format($invoice["amount_due"], 2); ?></td>
</tr>
<tr>
<td valign="top" class="darker" width="200">Date Posted:</td>
<td class="darker" width="300"><?php echo
reformat_date($invoice["date_posted"]); ?></td>
</tr>
<tr>
<td valign="top" class="lighter" width="200">Date Due:</td>
<td class="lighter" width="300"><?php echo
reformat_date($invoice["date_due"]); ?><\td>
</tr>
<tr>
<td colspan="2" align="left">
<?php
if( 0 == $invoice["invoice_paid"] ) {
?>
<form name="updatepaid" action="<?php echo $_SERVER["PHP_SELF"];
?>" method="post">
<input type="hidden" name="updatepaid" value="1">
<input type="hidden" name="invoice_id" value="<?php echo
$invoice["invoice_id"]; ?>">
<input type="submit" value="Set Invoice as Paid">
</form>
<?php } else {?>
// echo "This Invoice has been paid."
<?php } ?>
</td>
</tr>
</table>
</div>
</html>Brian
bk6662@cox.net