Re: [PHP] Number Sign in String Variables

2003-01-18 Thread Joab Stieglitz
OK.  I found the problem, and it isn't PHP or MySQL related.  It's an HTML
problem.  I'm passing the string from one script to another, and the # sign
is screwing up the URL.

For example, this URL:

add_to_cart.php?item_num=SOU3432410quantity=1sale_price=24.92unit=BX
short_desc=ENVELOPE,25%COT 24#,IYwholesaler=UScost=18.690

gets cut off at the # sign, so $wholesaler and $cost come out empty.

Any suggestions to get around this?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Number Sign in String Variables

2003-01-18 Thread Brad Pauly
 For example, this URL:
 
 add_to_cart.php?item_num=SOU3432410quantity=1sale_price=24.92unit=BX
 short_desc=ENVELOPE,25%COT 24#,IYwholesaler=UScost=18.690
 
 gets cut off at the # sign, so $wholesaler and $cost come out empty.
 
 Any suggestions to get around this?

You could use urlencode() and urldecode().

http://www.php.net/manual/en/function.urlencode.php
http://www.php.net/manual/en/function.urldecode.php

Brad



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Number Sign in String Variables

2003-01-18 Thread Joab Stieglitz
OK.  I urlencoded the URL and now the URL passes correctly...

add_to_cart.php%3Fitem_num%3DSTT32700%26quantity%3D1%26sale_price%3D52.78%26
unit%3DBX%26short_desc%3DENVELOPE%2C100%25COT%2024%23%2CGY%26wholesaler%3DUS
%26cost%3D37.700

... but I get the following error:

Forbidden
You don't have permission to access
/carmae/add_to_cart.php?item_num=STT32700quantity=1sale_price=52.78unit=B
Xshort_desc=ENVELOPE,100%COT 24#,GYwholesaler=UScost=37.700 on this
server.

I've never seen anything like this before.

Suggestions?

Brad Pauly [EMAIL PROTECTED] wrote in message
1042912825.15063.33.camel@earth">news:1042912825.15063.33.camel@earth...
  For example, this URL:
 
  add_to_cart.php?item_num=SOU3432410quantity=1sale_price=24.92unit=BX
  short_desc=ENVELOPE,25%COT 24#,IYwholesaler=UScost=18.690
 
  gets cut off at the # sign, so $wholesaler and $cost come out empty.
 
  Any suggestions to get around this?

 You could use urlencode() and urldecode().

 http://www.php.net/manual/en/function.urlencode.php
 http://www.php.net/manual/en/function.urldecode.php

 Brad





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Number Sign in String Variables

2003-01-18 Thread John W. Holmes
 OK.  I urlencoded the URL and now the URL passes correctly...
 

add_to_cart.php%3Fitem_num%3DSTT32700%26quantity%3D1%26sale_price%3D52.7
8%
 26

unit%3DBX%26short_desc%3DENVELOPE%2C100%25COT%2024%23%2CGY%26wholesaler%
3D
 US
 %26cost%3D37.700
 
 ... but I get the following error:
 
 Forbidden
 You don't have permission to access

/carmae/add_to_cart.php?item_num=STT32700quantity=1sale_price=52.78un
it
 =B
 Xshort_desc=ENVELOPE,100%COT 24#,GYwholesaler=UScost=37.700 on this
 server.
 
 I've never seen anything like this before.

And the line you get that error looks like? It looks like you're trying
to fopen() a file that's made up of PHP_SELF and the QUERY_STRING.

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Fwd: Re: [PHP] Number Sign in String Variables]

2003-01-18 Thread Brad Pauly
Oops...

-Forwarded Message-

From: Brad Pauly [EMAIL PROTECTED]
To: Joab Stieglitz [EMAIL PROTECTED]
Subject: Re: [PHP] Number Sign in String Variables
Date: 18 Jan 2003 16:40:40 -0700

 OK.  I urlencoded the URL and now the URL passes correctly...
 
 add_to_cart.php%3Fitem_num%3DSTT32700%26quantity%3D1%26sale_price%3D52.78%26
 unit%3DBX%26short_desc%3DENVELOPE%2C100%25COT%2024%23%2CGY%26wholesaler%3DUS
 %26cost%3D37.700
 
 ... but I get the following error:
 
 Forbidden
 You don't have permission to access
 /carmae/add_to_cart.php?item_num=STT32700quantity=1sale_price=52.78unit=B
 Xshort_desc=ENVELOPE,100%COT 24#,GYwholesaler=UScost=37.700 on this
 server.

Your web server is trying to find a directory with that long name. If
you encode the entire string, you need to pass it in a new variable,
then break it apart again.
 
 Suggestions?

Sorry, I gave some bad advice the first time. All you need to do is
urlencode each of the variables individually. Something like this:

$item_num_encoded = urlencode($item_num);
[...]

Then your link will be something like this:

add_to_cart.php?item_num=$item_num_encoded


Brad







-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Number Sign in String Variables

2003-01-18 Thread Steve Edberg
You need to urlencode() selectively; in this case, only the 
short_desc needs to be encoded, so you would have a statement 
something like

	echo
	add_to_cart.php?item_num=$item_numquantity=$quantity.
	sale_price=$sale_priceunit=$unitshort_desc=.
	url_encode($short_desc).wholesaler=$wholesalercost=$cost
	;

You need to encode any parameter (everything to the right of that 
first '?') that might include the '?', ''. '#' or space characters, 
since those all mean something special in a URL. To be safe, it's 
best to encode everything - or at least all strings. However, you 
have to encode them individually, since you need the UNencoded '' 
between them to delimit parameters, and you need that '?' there to 
indicate the start of the parameters.

I don't know the details of your program design, but there may be no 
reason to pass all the item details (description, sale price, etc.) 
in the URL anyway. Can't you just look them up in the add_to_card.php 
page, based on the item_num? Thus, all you need to pass are the 
quantity  item_number:

	echo add_to_cart.php?item_num=$item_numquantity=$quantity;

For one thing, that would eliminated the possibility of someone 
trying to get everything for free by manually typing a URL like

	add_to_cart.php?item_num=SOU3432410quantity=1sale_price=0unit=...

-steve


At 6:29 PM -0500 1/18/03, Joab Stieglitz wrote:
OK.  I urlencoded the URL and now the URL passes correctly...

add_to_cart.php%3Fitem_num%3DSTT32700%26quantity%3D1%26sale_price%3D52.78%26
unit%3DBX%26short_desc%3DENVELOPE%2C100%25COT%2024%23%2CGY%26wholesaler%3DUS
%26cost%3D37.700

... but I get the following error:

Forbidden
You don't have permission to access
/carmae/add_to_cart.php?item_num=STT32700quantity=1sale_price=52.78unit=B
Xshort_desc=ENVELOPE,100%COT 24#,GYwholesaler=UScost=37.700 on this
server.

I've never seen anything like this before.

Suggestions?

Brad Pauly [EMAIL PROTECTED] wrote in message
1042912825.15063.33.camel@earth">news:1042912825.15063.33.camel@earth...

  For example, this URL:
 

   add_to_cart.php?item_num=SOU3432410quantity=1sale_price=24.92unit=BX
   short_desc=ENVELOPE,25%COT 24#,IYwholesaler=UScost=18.690

 
  gets cut off at the # sign, so $wholesaler and $cost come out empty.
 
  Any suggestions to get around this?

 You could use urlencode() and urldecode().

 http://www.php.net/manual/en/function.urlencode.php
 http://www.php.net/manual/en/function.urldecode.php

 Brad






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
++
| Steve Edberg  [EMAIL PROTECTED] |
| University of California, Davis  (530)754-9127 |
| Programming/Database/SysAdmin   http://pgfsun.ucdavis.edu/ |
++
| SETI@Home: 1001 Work units on 23 oct 2002  |
| 3.152 years CPU time, 3.142 years SETI user... and STILL no aliens...  |
++

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Number Sign in String Variables

2003-01-18 Thread Joab Stieglitz
All I'm doing is making a hyperlink that sends the selected item from the
catalog to the add to shopping cart script.  The code now looks like this...

  $value = rawurlencode(add_to_cart.php?item_num= . $item_num .
quantity=1sale_price= . $our_price .
unit= . $unit .
short_desc= . $short_desc .
wholesaler= . $wholesaler .
cost= . $cost);

  echo /tdtda href=\ . $value .
   \ img src=\cart.jpg\Add/a\n/td/tr;

... and executes the link when the user clicks on the shopping cart icon.

John W. Holmes [EMAIL PROTECTED] wrote in message
002301c2bf4b$bc44c0b0$7c02a8c0@coconut">news:002301c2bf4b$bc44c0b0$7c02a8c0@coconut...

 And the line you get that error looks like? It looks like you're trying
 to fopen() a file that's made up of PHP_SELF and the QUERY_STRING.

 ---John W. Holmes...



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Number Sign in String Variables

2003-01-17 Thread John W. Holmes
 I have a MySQL database that includes data with the # sign in some
data
 fields.  My PHP script pulls the data out of the database fine, but
when I
 got to write back to the database, I get errors because the string
gets
 truncated at the # sign.  For example:
 
  $query = INSERT INTO order_detail
SET customer_id = -1,
order_id = $order_no,
item_id = $item_id,
item_num = \$item_num\,
unit = \$unit\,
short_desc = \$short_desc\,
quantity = $quantity,
wholesaler = \$wholesaler\,
cost = $cost,
sale_price = $sale_price;
 
 This statement fails if $short_desc contains a # sign.  The string
stops
 at
 the # sign, and all the subsequent fields are empty or garbage.
 
 None of the various resources I have looked at indicate that the #
sign is
 a
 special character.  Any suggestions?

# is used to start a comment in MySQL.

Show your actual code around this statement where you make your query.
The only reason the data would be cut off is if MySQL is interpreting
the # as the beginning of a comment. But, if that was the case, you'd
have an invalid query, so it must be a combination of things. 

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php