Jump to content

Recommended Posts

Hi! I'm new to PHP so apologies if I'm asking noob-like questions. I wrote out and ran the following code and received an error on line 37. Unfortunately, using terminal to debug is inefficient. Any help would be appreciated!..:

 

 

<!DOCTYPE html PUBLIC

"-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Save Invoice</title>

<link rel="stylesheet" href="php_styles.css" type="text/css" />

<meta http-equiv="content-type"

content="text/html; charset=iso-8859-1" />

</head>

<body>

<?php

$BillTo = $_POST["billto"];

$Date = $_POST["date"];

$Terms = $_POST["terms"];

$Description1 = $_POST["description1"];

$Description2 = $_POST["description2"];

$Description3 = $_POST["description3"];

$InvoiceNum = $_POST["invoicenum"];

$Quantity1 = $_POST["quantity1"];

$Quantity2 = $_POST["quantity2"];

$Quantity3 = $_POST["quantity3"];

$Rate1 = $_POST["rate1"];

$Rate2 = $_POST["rate2"];

$Rate3 = $_POST["rate3"];

$Amount1 = $_POST["amount1"];

$Amount2 = $_POST["amount2"];

$Amount3 = $_POST["amount3"];

$Total = $_POST["total"];

if (empty($BillTo) ||
empty($Date) ||
empty($Terms) ||
empty($Description1) ||
empty($Description2) ||
empty($Description3) ||
echo "<hr/><p>You must enter a value in each field. Click your browser's Back button to return to the invoice.</p><hr />";
else if (!is_numeric($InvoiceNum) ||
!is_numeric($Quantity1) ||
!is_numeric($Quantity2) ||
!is_numeric($Quantity3) ||
!is_numeric($Rate1) ||
!is_numeric($Rate2) ||
!is_numeric($Rate3) ||
!is_numeric($Amount1) ||
!is_numeric($Amount2) ||
!is_numeric($Amount3) ||
!is_numeric($Total))
echo "<p>You have an error! Please click on your browser's Back button to return to the form.</p>";
	else {
	$InvoiceFile = fopen($InvoiceNum . ".txt", "w") ;
	echo "<h1>Invoice Saved</h1>";

	echo "<hr /><br /><table frame='border' rules='rows'>";

	echo "<tr><td><strong>Bill To</strong>";

	echo "<pre>$BillTo</pre></td>";

	echo "<td style='text-align: right' colspan='3'>";

	echo "<br /><strong>Invoice #</strong>: $InvoiceNum<br />";

	echo "<strong>Date</strong>: $Date<br />";

	echo "<strong>Terms</strong>: $Terms</td></tr>";

	echo "<tr>";

	echo "<td><strong>Description</strong><br />$Description1<br />$Description2<br />$Description3</td>";

	echo "<td style='text-align: right'><strong>Quantity</strong><br />$Quantity1<br />$Quantity2<br />$Quantity3</td>";

	echo "<td style='text-align: right'><strong>Rate</strong><br />$$Rate1<br />$$Rate2<br />$$Rate3</td>";

	echo "<td style='text-align: right'><strong>Amount</strong><br />$$Amount1<br />$$Amount2<br />$$Amount3</td></tr>";

	echo "<tr><td colspan='4' style='text-align: right'><strong>TOTAL</strong>: $$Total</td></tr>";

	echo "</table>";

?>

<hr />

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/152334-question-on-debugging/
Share on other sites

You dont close the if:

if (empty($BillTo) ||
empty($Date) ||
empty($Terms) ||
empty($Description1) ||
empty($Description2) ||
empty($Description3) ||
echo "<hr/><p>You must enter a value in each field. Click your browser's Back button to return to the invoice.</p><hr />";
//...

 

Also, you don't close your last else statement.

using terminal to debug is inefficient
You should be developing and debugging code on a local PC that has a web server, php, and if needed mysql. These can be installed individually (for those wanting to learn how), or as a package - http://www.apachefriends.org/en/xampp.html

 

Posting the actual error would help someone to be able to help you.

I'm guessing you still didn't close that first statement correctly.

<!DOCTYPE html PUBLIC

"-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Save Invoice</title>

<link rel="stylesheet" href="php_styles.css" type="text/css" />

<meta http-equiv="content-type"

content="text/html; charset=iso-8859-1" />

</head>

<body>

<?php

$BillTo = $_POST["billto"];

$Date = $_POST["date"];

$Terms = $_POST["terms"];

$Description1 = $_POST["description1"];

$Description2 = $_POST["description2"];

$Description3 = $_POST["description3"];

$InvoiceNum = $_POST["invoicenum"];

$Quantity1 = $_POST["quantity1"];

$Quantity2 = $_POST["quantity2"];

$Quantity3 = $_POST["quantity3"];

$Rate1 = $_POST["rate1"];

$Rate2 = $_POST["rate2"];

$Rate3 = $_POST["rate3"];

$Amount1 = $_POST["amount1"];

$Amount2 = $_POST["amount2"];

$Amount3 = $_POST["amount3"];

$Total = $_POST["total"];

if (empty($BillTo) ||
empty($Date) ||
empty($Terms) ||
empty($Description1) ||
empty($Description2) ||
empty($Description3))
echo "<hr/><p>You must enter a value in each field. Click your browser's Back button to return to the invoice.</p><hr />";
else if (!is_numeric($InvoiceNum) ||
!is_numeric($Quantity1) ||
!is_numeric($Quantity2) ||
!is_numeric($Quantity3) ||
!is_numeric($Rate1) ||
!is_numeric($Rate2) ||
!is_numeric($Rate3) ||
!is_numeric($Amount1) ||
!is_numeric($Amount2) ||
!is_numeric($Amount3) ||
!is_numeric($Total))
echo "<p>You have an error! Please click on your browser's Back button to return to the form.</p>";
	else {
	$InvoiceFile = fopen($InvoiceNum . ".txt", "w") ;
	echo "<h1>Invoice Saved</h1>";

	echo "<hr /><br /><table frame='border' rules='rows'>";

	echo "<tr><td><strong>Bill To</strong>";

	echo "<pre>$BillTo</pre></td>";

	echo "<td style='text-align: right' colspan='3'>";

	echo "<br /><strong>Invoice #</strong>: $InvoiceNum<br />";

	echo "<strong>Date</strong>: $Date<br />";

	echo "<strong>Terms</strong>: $Terms</td></tr>";

	echo "<tr>";

	echo "<td><strong>Description</strong><br />$Description1<br />$Description2<br />$Description3</td>";

	echo "<td style='text-align: right'><strong>Quantity</strong><br />$Quantity1<br />$Quantity2<br />$Quantity3</td>";

	echo "<td style='text-align: right'><strong>Rate</strong><br />$$Rate1<br />$$Rate2<br />$$Rate3</td>";

	echo "<td style='text-align: right'><strong>Amount</strong><br />$$Amount1<br />$$Amount2<br />$$Amount3</td></tr>";

	echo "<tr><td colspan='4' style='text-align: right'><strong>TOTAL</strong>: $$Total</td></tr>";

	echo "</table>";
}
?>

<hr />

</body>

</html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.