GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-Nov-2007, 07:19
oggie oggie is offline
New Member
 
Join Date: Nov 2007
Location: tattershall, UK
Posts: 23
oggie is on a distinguished road
Unhappy

calculator


Hi to you all. I am a new member and am seeking some help please!!!

I currently trying to create a calculator that performs calculations for tax, quantity and price. I am having a problem with a message which comes up saying:

Parse error: syntax error, unexpected T_VARIABLE in /home/ogl09b7/public_html/includes/calculator.php on line 10

I have included the code for which I am to do. As you csn see it is all there,but I cannot see what is wrong with the line of code it is saying. look at calculate the results.

Here it is:

PHP Code:

<?php # calculator.php
$page_title = 'Widget Cost Calculator';
include ('../includes/header.html');
// Check if the form has been submitted.
if (isset($_POST['submitted'])) {
// Minimal form validation.
if ( is_numeric($_POST['quantity']) && is_numeric($_POST['price'] && is_numeric($_POST['tax']) ) 

// Calculate the results.
$taxrate = $_POST['tax'] / 100; // Turn 5% into .05.
$total = ($_POST['quantity'] * $_POST['price']) * ($taxrate + 1);

// Print the results.
echo '<h1 id="mainhead"> Total Cost</h1>
<p> the total cost of purchasing ' . $_POST['quantity'] . ' widget(s) at $' . number_format ($_POST['price'], 2) . ' each, including a tax rate of ' . $_POST['tax'] . '%, is $' . number_format ($total, 2) . ' .</p><p><br /></p>';
} else { // Invalid submitted values.
echo '<h1 id="mainhead">Error!</h1>
<p class="error>Please enter a valid quantity, price and tax.</p><p><br /></p>';
}

} //End of main isset() IF.

// Leave the PHP section and create the HTML form.
?>
<h2>Widget Cost Calculator</h2>
< form action="calculator.php" method="post">
<p>Quantity: <input type="text" name="quantity" size="5" maxlength="10" /></p>
<p>Price: <input type="text" name="price" size="5" maxlength="10" /></p>
<p>Tax (%): <input type="text" name="tax" size="5" maxlength="10" /></p>
<p>input type= "submit" name="submit" value="Calculate!" /></p>

<input type= "hidden" name="submitted" value="TRUE" />

</form>

<?php
include ('../includes/footer.html');
?>


Please can you help me on this. thanks

oggie
Last edited by LuciWiz : 11-Nov-2007 at 09:54. Reason: Please insert your Php code between [php] & [/php] tags
  #2  
Old 10-Nov-2007, 09:04
Kimmo Kimmo is offline
Member
 
Join Date: Mar 2007
Location: Finland
Posts: 229
Kimmo has a spectacular aura aboutKimmo has a spectacular aura about

Re: calculator


Quote:
Originally Posted by oggie
Parse error: syntax error, unexpected T_VARIABLE in /home/ogl09b7/public_html/includes/calculator.php on line 10

I have included the code for which I am to do. As you csn see it is all there,but I cannot see what is wrong with the line of code it is saying. look at calculate the results.
The error means the interpreter encountered a variable where it expected to encounter something else; hence, unexpected.

Usually in programs the errors are not on lines the error messages point at. The error message is generated when the interpreter / compiler cannot "put together" into a sensible statement what it has previously read and what it is reading right now. So, instead, look at the previous lines and see if your parentheses match. Use an editor with syntax highlighting. Notepad++ for example is an okay choice, with support to multiple languages.
__________________
Music, programming, endless learning..
  #3  
Old 10-Nov-2007, 10:13
oggie oggie is offline
New Member
 
Join Date: Nov 2007
Location: tattershall, UK
Posts: 23
oggie is on a distinguished road
Smile

Re: calculator


Thank you for replying will have a look now and let you know how i get on
  #4  
Old 10-Nov-2007, 11:08
oggie oggie is offline
New Member
 
Join Date: Nov 2007
Location: tattershall, UK
Posts: 23
oggie is on a distinguished road

select date form. Please help!! thanks


Hi Kimmo, I have another problem which I have encountered. Hope you can help me. I am trying to produce select a date. I have the days,years working but not the months. It all comes out in a line and not as a <select>. I have used a foreach loop. I have copied into here so can you or anyone else have a look, as I cannot see where the problem is.

PHP Code:

<?php # script 3.7 - dateform.php
$page_title = 'Calendar Form';
include ('../includes/header.html');

// This function makes three pull-down menus for the months, days, and years.

function make_calendar_pulldowns() {

// Make the months array.

$months = array (1 => 'January', 'Febuary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

// Make the months pull down-menu.

echo '<select name="month">';
foreach ($months as $key => $value) {
echo "<option value=\"$key\">
$value</option>\n";

}

echo '</select>';

// Make the days pull-down menu.

echo '<select name="day">';
for ($day = 1; $day <=31; $day++) {
echo "<option value=\"$day\">$day</option>\n";

}

echo '</select>';

// Make the years pull-down menu.

echo '<select name="year">';
for ($year= 2007; $year <=2012; $year++) {
echo "<option value=\"$year\">$year</option>\n";

}

echo '</select>';

} //End of the function definition.

// Create the form tags.

echo '<h1 id="mainhead">Select a Date:</h1>
<p><br /></p><form action="dateform.php" 
method="post"';

// Call the function.

make_calendar_pulldowns();

echo '</form><p><br /></p>'; // End of form.

include ('../includes/footer.html');

?>


oggie
Last edited by LuciWiz : 11-Nov-2007 at 09:55. Reason: Please insert your Php code between [php] & [/php] tags
  #5  
Old 11-Nov-2007, 05:24
filth filth is offline
New Member
 
Join Date: Oct 2007
Posts: 5
filth is on a distinguished road

Re: calculator


if you run the code and look at the source you will see that you have a line such as:-

<form action="dateform.php"
method="post"<select name="month"><option value="1"

notice the form tag has not been closed. In your code find where <form action="dateform.php" is being generated and put a > after "dateform.php"
  #6  
Old 26-Nov-2007, 07:51
oggie oggie is offline
New Member
 
Join Date: Nov 2007
Location: tattershall, UK
Posts: 23
oggie is on a distinguished road

Re: calculator


Thanks filth. i did not see that tag missing. Looks good now. Hope I can be of use some time to you in the future. Oggie
 
 

Recent GIDBlogFlickr uploads of IA pictures by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Flex, bison multifunction calculator annatsos C Programming Language 6 03-May-2007 10:50
Try to post the code of this program plzzz..Calculator is hard to solve!!! albert_123 C Programming Language 3 21-Sep-2006 02:41
Simple Calculator Application MOHAMMEDALI1989 Java Forum 1 06-Oct-2005 17:00
C (not C++) calculator conghaile C Programming Language 0 18-Apr-2005 11:15

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:20.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.