Got A Wee Error - Can You Help?

Pages: 1, 2
free web hosting

Read Latest Entries..: (Post #13) by ginginca on Oct 31 2006, 11:27 AM. (Line Breaks Removed)
Yes I see what you mean about the amount of code, and the page is already a bit of a monster.I'm thinking of making a function for it, and then putting it on a require_once page.I went with the number format because it looked like less coding. I originally tried the money_format but had errors. On my PC I have PHP5 installed.BTW, can you be online when I do my exam next month? (Just kidding... read more.
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Got A Wee Error - Can You Help?

ginginca
I'm taking a PHP course at college and am working on an assignment. There's no database involved.

I've declared my variables from a submit form on another page, and on the page I'm working on I'm trying to bring them up in a table. But my start-table command is outputting an error. Here's the code relating to where the error is:

CODE
<?php

//Get First Item
    if (isset($_GET['item_1_product'])) {        
        $item_1_product = $_GET['item_1_product'];
    } else {
        $item_1_product = ""; //Default value if data missing
    }
    
    if (isset($_GET['item_1_price'])) {        
        $item_1_price = $_GET['item_1_price'];
    } else {
        $item_1_price = ""; //Default value if data missing
    }
    
    if (isset($_GET['item_1_purchased'])) {        
        $item_1_purchased = $_GET['item_1_purchased'];
    } else {
        $item_1_purchased = ""; //Default value if data missing
    }
    
    if (isset($_GET['item_1_size'])) {        
        $item_1_size = $_GET['item_1_size'];
    } else {
        $item_1_size = ""; //Default value if data missing
    }
    
    if (isset($_GET['item_1_qty'])) {        
        $item_1_qty = $_GET['item_1_qty'];
    } else {
        $item_1_qty = ""; //Default value if data missing
    }

    
    //Get Second Item
    if (isset($_GET['item_2_product'])) {        
        $item_2_product = $_GET['item_2_product'];
    } else {
        $item_2_product = ""; //Default value if data missing
    }
    
    if (isset($_GET['item_2_price'])) {        
        $item_2_price = $_GET['item_2_price'];
    } else {
        $item_2_price = ""; //Default value if data missing
    }
    
    if (isset($_GET['item_2_purchased'])) {        
        $item_2_purchased = $_GET['item_2_purchased'];
    } else {
        $item_2_purchased = ""; //Default value if data missing
    }
    
    if (isset($_GET['item_2_size'])) {        
        $item_2_size = $_GET['item_2_size'];
    } else {
        $item_2_size = ""; //Default value if data missing
    }
    
    if (isset($_GET['item_2_qty'])) {        
        $item_2_qty = $_GET['item_2_qty'];
    } else {
        $item_2_qty = ""; //Default value if data missing
    }
    
    //Get Third Item
    if (isset($_GET['item_3_product'])) {        
        $item_3_product = $_GET['item_3_product'];
    } else {
        $item_3_product = ""; //Default value if data missing
    }
    
    if (isset($_GET['item_3_price'])) {        
        $item_3_price = $_GET['item_3_price'];
    } else {
        $item_3_price = ""; //Default value if data missing
    }
    
    if (isset($_GET['item_3_purchased'])) {        
        $item_3_purchased = $_GET['item_3_purchased'];
    } else {
        $item_3_purchased = ""; //Default value if data missing
    }
    
    if (isset($_GET['item_3_qty'])) {        
        $item_3_qty = $_GET['item_3_qty'];
    } else {
        $item_3_qty = ""; //Default value if data missing
    }
    
            
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en" />
<meta name="GENERATOR" content="Zend Studio" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Process Order</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#FF9966" vlink="#FF9966" alink="#FFCC99">
    
    
    <table align ="center" cellpadding="1" cellspacing="1" width="550" border="0">
    <tr>
        <td colspan="5" height="50" align="center" valign="middle">
        <font size="4" face="Arial, Helvetica, sans-serif"><B>Products Ordered</B></font><BR>
        
        </td>
    </tr>
    <tr bgcolor="#CCCCCC">
                <td align="center" valign="middle" width="200"><font size="2" color="Blue" face="Arial, Helvetica, sans-serif"><B>Product Name</B></font></td>
        <td align="center" valign="middle" width="100"><font size="2" color="Blue" face="Arial, Helvetica, sans-serif"><B>Price</B></font></td>
        <td align="center" valign="middle" width="100"><font size="2" color="Blue" face="Arial, Helvetica, sans-serif"><B>Size</B><BR>(S, M, L or XL)</font></td>
        <td align="center" valign="middle" width="100"><font size="2" color="Blue" face="Arial, Helvetica, sans-serif"><B>Qty</B></font></td>
        <td align="center" valign="middle" width="100"><font size="2" color="Blue" face="Arial, Helvetica, sans-serif"><B>Subtotal</B></font></td>
    </tr>
    <tr bgcolor="#EEEEEE">
        <td align="center" valign="middle" width="200"><font size="2" face="Arial, Helvetica, sans-serif"><?php print $item_1_product; ?></font></td>
        <td align="center" valign="middle" width="100"><font size="2" face="Arial, Helvetica, sans-serif"><?php print $item_1_price; ?></font></td>
        <td align="center" valign="middle" width="100"><font size="2" face="Arial, Helvetica, sans-serif"><?php print $item_1_size; ?></td>
        <td align="center" valign="middle" width="100"><font size="2" face="Arial, Helvetica, sans-serif"><?php print $item_1_qty; ?></td>        
        <td></td>
    </tr>
    <tr>
        <td align="center" valign="middle" width="200"><font size="2" face="Arial, Helvetica, sans-serif"><?php print $item_2_product; ?></font></td>
        <td align="center" valign="middle" width="100"><font size="2" face="Arial, Helvetica, sans-serif"><?php print $item_2_price; ?></font></td>
        <td align="center" valign="middle" width="100"><font size="2" face="Arial, Helvetica, sans-serif">N/A</td>
        <td align="center" valign="middle" width="100"><font size="2" face="Arial, Helvetica, sans-serif"><?php print $item_2_qty; ?></td>        
        <td></td>
    </tr>
    <tr bgcolor="#EEEEEE">
        <td align="center" valign="middle" width="200"><font size="2" face="Arial, Helvetica, sans-serif"><?php print $item_3_product; ?></font></td>
        <td align="center" valign="middle" width="100"><font size="2" face="Arial, Helvetica, sans-serif"><?php print $item_3_price; ?></font></td>
        <td align="center" valign="middle" width="100"><font size="2" face="Arial, Helvetica, sans-serif"><?php print $item_3_size; ?></td>
        <td align="center" valign="middle" width="100"><font size="2" face="Arial, Helvetica, sans-serif"><?php print $item_3_qty; ?></td>        
        <td></td>
        
    </tr>
    
</table>
    
    
    
    

</body>
</html>



(1) I'm getting no values coming up on this page when I submit.

(2) Am I doing this correctly where I start and stop php continually down the page?

Thanks,

Gin

 

 

 


Reply

jlhaslip
The way you are using the php start/end tags is okay as far as I see. No problem there.
I am suspicious that the Form on the other page is faulty, or the variable names are messed up?

As a test, add and echo command into your code like so:
CODE

echo 'start';
echo "$_GET['item_1_product']";
echo 'end';
//Get First Item
    if (isset($_GET['item_1_product'])) {        
        $item_1_product = $_GET['item_1_product'];
    } else {


This will tell you if the variables are being passed as you expect them to be passed.

Reply

vujsa
Yeah, so no major problems with the code provided!

If you manually input variables in the url, everything works fine. smile.gif
ginginca.php?item_1_product=Baseball%20Cap&item_1_price=$1.00&item_1_size=XL&item_1_qty=200

This url correctly displayed "Name", "Price", "Size", and "Quantity" for item one in the table. Try a manual url entry to see for yourself!

The real issue must be in the form that submits the data. I'm guessing that your form uses the "POST" method and your script uses the "GET" method! Can't be sure until I see the submisstion form.

Now on to the basics. laugh.gif

In your table HTML, you never close many of your <font> tags. I'm guessing that that will be considered by your professor.

By the way, not sure what your original assignment was but it seems like a lot of work to set all of your variables this way. Have you considered an array and a loop? Your PHP code would be about 10 lines long instead of 90. Just a thought.

vujsa

 

 

 


Reply

ginginca
Ah ... and you come to my rescue once again!

Here's the code for the entry page.

I'll post them online and try them there in case there's an issue with my PHP running on the PC here.

CODE

<?php
/**
* Student Assignment - Chapter 4
* Order Form
*
*/
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en" />
<meta name="GENERATOR" content="Zend Studio" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Order Form</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#FF9966" vlink="#FF9966" alink="#FFCC99">
<form id="MyOrder" action="process_order.php" method="POST">
<table align ="center" cellpadding="1" cellspacing="1" width="550" border="0">
    <tr>
        <td colspan="5" height="50" align="center" valign="middle">
        <font size="4" face="Arial, Helvetica, sans-serif"><B>Order Form</B></font><BR>
        <font size="2" color="Red" face="Arial, Helvetica, sans-serif">Check off the products you wish to purchase.</font>
        </td>
    </tr>
    <tr bgcolor="#CCCCCC">
        <td align="center" valign="middle" width="50"><font size="2" color="Blue" face="Arial, Helvetica, sans-serif"><B>Select Items</B></font></td>
        <td align="center" valign="middle" width="200"><font size="2" color="Blue" face="Arial, Helvetica, sans-serif"><B>Product Name</B></font></td>
        <td align="center" valign="middle" width="100"><font size="2" color="Blue" face="Arial, Helvetica, sans-serif"><B>Price</B></font></td>
        <td align="center" valign="middle" width="100"><font size="2" color="Blue" face="Arial, Helvetica, sans-serif"><B>Size</B><BR>(S, M, L or XL)</font></td>
        <td align="center" valign="middle" width="100"><font size="2" color="Blue" face="Arial, Helvetica, sans-serif"><B>Qty</B></font></td>
    </tr>
    <tr bgcolor="#EEEEEE">
        <input type="hidden" name="item_1_product" value="Zend Studio T-Shirt"/>
        <input type="hidden" name="item_1_price" value="14.45"/>  
        <td align="center" valign="middle" width="50"><input type="checkbox" name="item_1_purchased" value="YES"/></td>
        <td align="center" valign="middle" width="200"><font size="2" face="Arial, Helvetica, sans-serif">Zend Studio T-Shirt</font></td>
        <td align="center" valign="middle" width="100"><font size="2" face="Arial, Helvetica, sans-serif">$14.45</font></td>
        <td align="center" valign="middle" width="100"><input type="text" name="item_1_size" size="5" value=""/></td>
        <td align="center" valign="middle" width="100"><input type="text" name="item_1_qty" size="5" value=""/></td>        
    </tr>
    <tr>
        <input type="hidden" name="item_2_product" value="Zend Studio Jacket"/>  
        <input type="hidden" name="item_2_price" value="125.75"/>
        <td align="center" valign="middle" width="50"><input type="checkbox" name="item_2_purchased" value="YES"/></td>
        <td align="center" valign="middle" width="200"><font size="2" face="Arial, Helvetica, sans-serif">Zend Studio Jacket</font></td>
        <td align="center" valign="middle" width="100"><font size="2" face="Arial, Helvetica, sans-serif">$125.75</font></td>
        <td align="center" valign="middle" width="100"><input type="text" name="item_2_size" size="5" value=""/></td>
        <td align="center" valign="middle" width="100"><input type="text" name="item_2_qty" size="5" value=""/></td>        
    </tr>
    <tr bgcolor="#EEEEEE">
        <input type="hidden" name="item_3_product" value="Zend Studio Mug"/>  
        <input type="hidden" name="item_3_price" value="7.95"/>
        <td align="center" valign="middle" width="50"><input type="checkbox" name="item_3_purchased" value="YES"/></td>
        <td align="center" valign="middle" width="200"><font size="2" face="Arial, Helvetica, sans-serif">Zend Studio Mug</font></td>
        <td align="center" valign="middle" width="100"><font size="2" face="Arial, Helvetica, sans-serif">$7.95</font></td>
        <td align="center" valign="middle" width="100"><font size="2" face="Arial, Helvetica, sans-serif">N/A</font></td>
        <td align="center" valign="middle" width="100"><input type="text" name="item_3_qty" size="5" value=""/></td>        
    </tr>
    <tr>
        <td colspan="5" height="40" align="center" valign="middle">
        <input type="submit" name="submit" value="Order Now!"/>  
        </td>
    </tr>
</table>
</form>
</body>
</html>


Reply

ginginca
http://www.vividelements.com/school/order_form.php

Same thing online as it was doing on my PC.


Reply

vujsa
QUOTE(ginginca @ Oct 28 2006, 07:00 PM) *

http://www.vividelements.com/school/order_form.php

Same thing online as it was doing on my PC.

Yeah, exactly as I suspected.. tongue.gif

In your form find on line #9:
HTML
<form id="MyOrder" action="process_order.php" method="POST">


If you use the "POST" method in your form, then to be able to used the passed variables in your "process_order.php" script, you have to use the "POST" method there as well!

So you need to change ALL of your $_GET in your script to $_POST!

OR

Change your form from "POST" to "GET"!

vujsa

Reply

ginginca
Of course you are absolutely correct and thank you. It works great now.

I have to learn a couple of concepts here.

(1) If I want to format my number output and don't have a programming background. Would I be looking to use the printf command? Or do I make my variable a float/double?

(2) I need to also learn to do some error-checking, using if statements.

I have a form that puts data into a database, but only want the submission to be processed if the 1st three digits of the phone number match from a list of two. The list will never change, so it doesn't have to be part of the database. (I'm going to put it into my form.) I plan on using a switch statement.

What I don't quite get, is WHERE in my form the if statement goes.

Thanks,

Gin


Reply

vujsa
Well, for your phone number issue, here is what I would do. Since this will be a true/false situation, and since false will terminate the process, you should put the check at the beginning of the script like so:
CODE

<?php
if (isset($_POST['phone'])){
    $phone_prefix = $substr($_POST['phone'], 0, 3);
    if($phone_prefix == 123 || $phone_prefix == 321){
        echo "Good Number!";
    }
    else{
        exit("Error! - Bad Phnoe Number!");
    }
}
else{
    exit("Error! - No Phone Number Entered!");
}
?>


Now what that does is check to see if the phone number starts with 321 or 123. If it doesn't start with 321 or 123 or if it isn't set, an error message is returned and the script ends

I'm not sure what it is that you need for your number format question.
If you give me an example of a number that you start with and also provide me with an example of the returned number, then I can tell you how to do it probably.

vujsa

Reply

ginginca
formatting ...

On my results page that you helped with yesterday (GET vs POST) I would like to format the numbers as $0.00.


Reply

ginginca
On my entry form regarding the phone number we were talking about, I am asking them only for the area code. I want to make sure that submissions are only from area code 519 and 226.

My field name is area_code

I want it to stop processing the form if the value is not one of the above.

But I will be also adding to the form, that if ANY of my fields are empty, not to submit it to the database. So I'm setting up a number of error checks.

My submit form and result page are on the same php page.

Does this make sense?

CODE
//Check All Required Variables To Make Sure They Are NOT Empty
    if (empty($name) or empty($cat) or empty($url) or
      empty($email) or empty($area_code) or empty($city)) {
    print "one or more required fields are mising";
    }

//Check area code for valid region
        if (int($area_code) !=519 or int($area_code) !=226) {
        print "area code is not valid for this region";
       }


And if so, I'm not sure where on the page it fits into the structure, since it is all done on the same page.


Here's where they submit from: http://www.londonlink.ca/submit_a_site.php





Reply

Latest Entries

ginginca
Yes I see what you mean about the amount of code, and the page is already a bit of a monster.

I'm thinking of making a function for it, and then putting it on a require_once page.

I went with the number format because it looked like less coding. I originally tried the money_format but had errors. On my PC I have PHP5 installed.

BTW, can you be online when I do my exam next month? (Just kidding.)



Gin

Reply

vujsa
Well, that is the correct code but it will not work on windows machines and you have to have PHP4.3.0 or higher. Since that is the correct code, I think it is better to use that instead of number_format if your system allows for it.

The code I gave you will use money_format if available but if not, it will use the number_format method!

I generally think that you should always use the correct code for the situation which isn't always possible so you have to have a backup plan. That is what my code will do for you.

But you are correct, if that was what was required to format a number, it would be a lot of code. This has a lot of optional code.

It is of course possible to format you numbers manually in several ways which WOULD require a lot more code and gets kind of tedious. My point is, there is always more than one way to code something!

Hope this helps.

vujsa

Reply

ginginca
That looks like quite a bit of code to format variables. I tried something this morning that didn't work:

QUOTE
<?php print money_format('%1', $item_1_price). '\n'; ?>


I was attempting to follow what was on php.net for the instructions. Do I have an error in this (above) or am I just completely wrong about how I am going about it?

Gin

This worked:
QUOTE

<?php echo '$' .number_format($item_1_price,2); ?>

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Pages: 1, 2
Similar Topics

Keywords : wee, error

  1. Php Configuration Error?
    (6)
  2. Cant Find The Error
    (2)
    In this code I want to retrieve the energy and max energy of a players account, then add 8% to
    energy of maxenergy, hen if energy is bigger than maxenergy, energy is then made equal to maxenergy.
    Then the database is updated. I don't understand why it's not working.
    $query=mysql_query("SELECT MAX(id) as maxid FROM `accounts` LIMIT 1"); $row =
    mysql_fetch_assoc($query); $id = $row ; $query = "SELECT * FROM `accounts`";
    $result=mysql_query($query); while ($row=mysql_fetch_assoc($result)) { $energy = $row ; $maxenergy
    = $row ; } for($i=1; $i $query = "SELECT....
  3. Php Error-where To Put "?>"
    (2)
    lol....lately i have many problems in writing my scripts and i dont know if i should create post
    only for purpose so ppl can help me or should i create many post like i am doing right now...i am
    NOT making this to get many credits...i am doing it because i need help and many people here help
    me! CODE if ($_GET !='race'){ Who do you wanna race?           Derbi Senda 50
         Honda NS 50 R      Suzuki ZR 50      Yamaha DT 50 MX      Aprilia RS 50      - ?        
    } i have this code...if i put after it i get QUOTE Parse error: syntax....
  4. Warning: Mysql_num_rows()
    What is the error :S (1)
    Hey! I've made a register script.. Some time ago it worked. And I ain't sure if I changed
    something since then.. The error I am getting is this: Warning: mysql_num_rows(): supplied argument
    is not a valid MySQL result resource in /home/feelay/public_html/regcheck.php on line 31 Here is
    the code on theese lines: CODE $sqlCheckForDuplicate = "SELECT username FROM user WHERE username
    = '". $username ."'";                 if( mysql_num_rows( mysql_query(
    $sqlCheckForDuplicate ) ) == 0 )         {             $sqlRegUser =     "INSERT INTO            ....
  5. Php Math Error
    (4)
    I cant get php to do simple math. Anyway
    I need to run a math problem from the mysql database (dont ask why). So lets say I have an entrie: 5
    +5. I get it from my db then eval it but nothing happens? How could I make it so that it runs the 5+
    5 rather then just displaying it? Thanks, Sparkx Also: I have no clue if it is just my browser or
    what but my post breaks to boarder for some odd reason?....
  6. Unexpected Error
    Undefined variable??? (2)
    Is this script correct? index.php : CODE     if (isset($_COOKIE ))           $_GET =
    $_COOKIE ;     else         setcookie("disp_name", Anonymous, date()+99); ?>              
    Display Name - DZN                                                                   
                    Dislpay Name: name="name" />                                                
         proccess.php : CODE      Proccessing Request...           Please wait...
        setcookie("disp_name", $_GET , date()+99); ?> main.php : CODE     function customErr....
  7. Error On Submit Page
    (10)
    I am writing a new submit page for one of my sites and am doing a few things to stretch my
    experience. I am getting an error (naturally.) Here is part pf the page where the error might be:
    CODE //Check to see if the web page called itself     if (strtoupper($action) == "CHECK") {
            //The web page called itself, so run the error checking code         //Declare a variable to
    hold the error messages     $error = '';      // variable names:    name, cat, sub_cat, url,
    date, status, email, other, area_code, city          $name = $_POST ;     $cat = $_P....
  8. E-mail List Error
    (4)
    I just coded this e-mail list, it works well for entering data into database, but if user leaves
    the field blank or adds an already exist e-mail it gives him the error message and stops loading the
    rest of the page. CODE // Connects to your Database mysql_connect("localhost", "my_username",
    "mypassword") or die(mysql_error()); mysql_select_db("Database name") or die(mysql_error()); //This
    code runs if the form has been submitted if (isset($_POST )) { //This makes sure they did not leave
    any fields blank if (!$_POST ) {die(' No e-mail added '); } ....
  9. In Php, How To Not Display Mysql Connection Error?
    Don't want mysql_connect() message (4)
    In PHP, if the mysql database server cannot be connected, for example database server is handed or
    turned off, an error message will be displayed: Warning: mysql_connect(): Unknown MySQL Server Host
    "mysql.example.com" ... My question is how to not display this warning message? or can I customise
    the error message? if so, how? Thank you.....
  10. Php Problem Error Message
    I'm working from a book (9)
    I get this error message when I try to view a small webpage. QUOTE Parse error: parse error,
    unexpected T_STRING, expecting ',' or ';' in
    /home/nilsc/public_html/bobs/processorder.php on line 27 Line 27 is in this php part: CODE
    echo ' Order processed. '; echo $tireqty. ' tires '; echo $oilqty. ' bottles
    of oil '; echo $sparkqty. ' spark plugs '; $totalqty = 0; $totalqty = $tireqty +
    $oilqty + $spakqty; echo 'Items ordered: ' .$totalqty.' ; $totalamount = 0.00;
    define('TIREPRICE....
  11. PHP paFileDB error
    an error relating to admin login (0)
    does any body know how to over come an error in paFileDB which says Warning: Cannot modify header
    information - headers already sent by (output started at
    /home/paltalkh/public_html/pafiledb/includes/mysql.php:86) in
    /home/paltalkh/public_html/pafiledb/includes/admin/login.php on line 36 Warning: Cannot modify
    header information - headers already sent by (output started at
    /home/paltalkh/public_html/pafiledb/includes/mysql.php:86) in
    /home/paltalkh/public_html/pafiledb/includes/admin/login.php on line 38 i have downloaded the php
    from phparena.net directly. Any hel....
  12. PHP paFileDB error
    an error relating to admin login. (2)
    does any body know how to over come an error in paFileDB which says Warning: Cannot modify header
    information - headers already sent by (output started at
    /home/paltalkh/public_html/pafiledb/includes/mysql.php:86) in
    /home/paltalkh/public_html/pafiledb/includes/admin/login.php on line 36 Warning: Cannot modify
    header information - headers already sent by (output started at
    /home/paltalkh/public_html/pafiledb/includes/mysql.php:86) in
    /home/paltalkh/public_html/pafiledb/includes/admin/login.php on line 38 i have downloaded the php
    from phparena.net directly. Any he....

    1. Looking for wee, error






*SIMILAR VIDEOS*
Searching Video's for wee, error
advertisement




Got A Wee Error - Can You Help?



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE