Jump to content


Photo

more problems with PHP string to HTML to $_GET to Query


  • Please log in to reply
4 replies to this topic

#1 Humpty

Humpty
  • Members
  • PipPipPip
  • Advanced Member
  • 132 posts

Posted 02 March 2006 - 09:07 AM

*** SOLVED *** (thanks to Ken)
(still can't work out how to mark this as solved)

G'day Guys

I am echoing a PHP string in HTML that is a URL.

Once that string is clicked on it passes info ($_GET) to the next PHP file. But somewhere between the file GETing the data and the file performing a query I lose a + (plus sign) that is in the field requirement.

e.g:

PHP:
$MyString="productnumber+11kk";

HTML:
<? echo "$MyString" ?>

The link:
filename.php?datatoget=productnumber+11kk

$_GET: When i use:
$MyString2=$_GET['datatoget'];

I end up withe $MyString2 storing "productnumber 11kk" and not "productnumber+1kk"

The record in the query has the plus sign in it. (after all that is where the original $Mystrng actually comes from)

Any ideas on how to stop the "+"(plus sign) turning into a " "(space character)...either by changing it before or the URL is displayed in href or after or while it is retrieved using the $_GET?

Thanks - Humpty
- Humpty
  #> Where does the light go when it goes out?

#2 willpower

willpower
  • Members
  • PipPipPip
  • Advanced Member
  • 296 posts
  • LocationWarrington, Cheshire, UK

Posted 02 March 2006 - 12:36 PM

try adding a \ before the +


Wait...I've got it...Bollocks, it's gone again!

If at first you don't succeed....stop using ASP and get onto PHP

#3 Humpty

Humpty
  • Members
  • PipPipPip
  • Advanced Member
  • 132 posts

Posted 02 March 2006 - 12:44 PM

nah the \ didn't help.

If anyone wants to fiddle with it the URL that it is is:

"partnum=DVD+R50" <--- there is the offending + sign. even when you type into the browser it doesn't work." The rest of the URL is fine. Is just the + converts to a space (in my code that is).


[a href=\"http://www.shop.teegee.net.au/ProductDetails.php?partnum=DVD+R50-16X&cat=DVDs%20and%20CDs&cat2=DVD-R//RW%20Media&cat3=\" target=\"_blank\"]http://www.shop.teegee.net.au/ProductDetai...W%20Media&cat3=[/a]
- Humpty
  #> Where does the light go when it goes out?

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 02 March 2006 - 05:02 PM

Unfortunately, a plus sign is translated into a space by urldecode() which is implicitly called for you. What you need to do is apply the function urlencode() to the string before putting it into the URL.

Example:
<?php
if (issset($_GET['test'])) echo '<pre>'.print_r($_GET,true).'</pre>';
$plus = 'This string has a plus (+) sign in it.';
$plus1 = urlencode($plus);
<a href="<?php echo $_SERVER['PHP_SELF'] ?>?test=<?php echo $plus ?>">Test 1</a><br />
<a href="<?php echo $_SERVER['PHP_SELF'] ?>?test=<?php echo $plus1 ?>">Test 2</a>
?>

Ken

#5 Humpty

Humpty
  • Members
  • PipPipPip
  • Advanced Member
  • 132 posts

Posted 03 March 2006 - 02:26 AM

G'day Ken,

I thought it didn't work but I was wrong


pffft......who am I to doubt you.

You rock thankyou very much will remember that for next time.
- Humpty
  #> Where does the light go when it goes out?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users