Current location: Hot Scripts Forums » Programming Languages » PHP » Newbie: PHP Assignment Please Help


Newbie: PHP Assignment Please Help

Reply
  #1 (permalink)  
Old 10-10-08, 08:51 AM
Schecter420 Schecter420 is offline
Newbie Coder
 
Join Date: Sep 2008
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Newbie: PHP Assignment Please Help

I am VERY new to php, I just started a class this semester I was hoping somebody could help me with a couple things because I dont have the book and I cant find the info on the internet. My assignment is very basic: a PHP program that calculates the total cost of a certain number of items input and outputs an error message if amount of money is not a number. My problems are: 1-How do I make it so no error message shows up if the text field is blank? 2-How do I get a correct error count (should understand what i mean from code, otherwise ill clarify). 3-How do I add up all the numbers in the table, everything ive tried always only outputs the last number (i HAVE to use the "for" statement, its part of the assignment).
here is my code so far:

PHP Code:

<html>
<head>
    <title>Bills</title>
</head>
<body>

<h1>My Bills</h1>
<br>

<form method=post>

<table>

<tr>
<th>Item</th>
<th>Amount</th>

<?php


for ($i 1$i 5$i++)
{

  
$item_name 'item'."$i";
  
$item_value $_POST[$item_name];
  
$price 'price'."$i";
  
$price_value $_POST[$price];
  



  print 
'<tr>';

  print 
"<td> <input type=text name=$item_name value=$item_value> </td>";
  print 
"<td> <input type=text name=$price value=$price_value> </td>";
  print 
"<td>";


  if(
is_numeric($price_value))
{
            
//add total bills
}

  else
{
    print 
"Amount $price_value is not a number";
    
            
//add 1 to error count
}

  if(
$price_value >= 100 && $price_value <= 100000)
{
            
//add total bills
}
  else
{
    print 
"Amount $price_value should be between 100 and 100000";
        
            
//add 1 to error count
}
    }

print 
"</td>";
print 
'</tr>';


?>

</table>
<br>

<input type=submit value=Submit>

<br><br>

<?php

  
if($error_count 0)
{
    print 
"<font color=#ff000>Errors: $error_count </font>";
}

  else
{
    print 
"Total: $total_bills";
}

?>

</form>
</body>
</html>
i realize some of the variables arent declared in the beginning, i erased a lot of code that wasn't working. i would appreciate any help. im a newbie and I have no idea what im doing.

Last edited by Nico; 10-10-08 at 09:03 AM. Reason: Wrappers.
Reply With Quote
  #2 (permalink)  
Old 10-10-08, 11:51 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by Schecter420 View Post
I am VERY new to php, I just started a class this semester I was hoping somebody could help me with a couple things because I dont have the book and I cant find the info on the internet.
1) Get the book, or any beginner's book on PHP.
2) Trust me, this information is on the internet. I guarantee it 100%.

Quote:
Originally Posted by Schecter420 View Post
i would appreciate any help. im a newbie and I have no idea what im doing.
We understand, but we cannot do your homework for you. That's the whole point of your being in school- to learn how to do something, not to learn how to get others to do it for you.

To add 2 items in PHP, you can do this:

PHP Code:

$var1 5;

$var2 10;

$answer = ($var1 $var2); 
The rest is up to you. Experiment, play around, see what happens. But please don't ask us to help fake your homework.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #3 (permalink)  
Old 10-11-08, 12:15 AM
Schecter420 Schecter420 is offline
Newbie Coder
 
Join Date: Sep 2008
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
I understand. Dont get the wrong idea though, I did fumble around with it for a long time and searched google, posting here was a last resort. The comments I put in there such as //add 1 to error count were spots where I tried different things and they didnt work out. All the other code I did write out myself so I am not COMPLETELY oblivious to php. i do want to learn php and i hate asking for help, the last thing I would want is someone doing my homework for me. anyway ill fumble around with it some more I know ill get it eventually
Reply With Quote
  #4 (permalink)  
Old 10-13-08, 08:35 PM
ianbrind ianbrind is offline
Wannabe Coder
 
Join Date: Jul 2008
Location: Somerset UK!
Posts: 192
Thanks: 0
Thanked 0 Times in 0 Posts
If you would like to me to give you a helping hand just drop me a message
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] it works on localhost but not on hosting account? myslowquietlife PHP 42 12-19-08 09:31 AM
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
FYI: Shout goes out over PHP security bugs nugensoftware PHP 0 11-01-05 11:43 PM
PHP Newbie NCC1701 New Members & Introductions 2 03-20-04 03:36 PM
Totally ignorant newbie needs help! Dawn_M_74 The Lounge 3 03-06-04 10:09 AM


All times are GMT -5. The time now is 08:21 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.