0

Hi I am trying to pass a value from one file to another file via URL.

The way i do is: <a href='fund_view.php?idfund="<? echo $row['idfund']; ?>"'>

after all i get the right value in other file using

$aidi = $_GET['idfund'];

echo 'ID= '.$aidi;`

But the result i get is this format ID= \"10\"

the url after i pass the id looks like

http://example.com/fund_view.php?idfund="10"

and what i want the result to be is just ID="10".

ghoti
  • 45,319
  • 8
  • 65
  • 104
Lulzim Fazlija
  • 865
  • 2
  • 16
  • 37

3 Answers3

2

Turn off magic_quotes in php.ini and you should get rid of those backslashes.

nickb
  • 59,313
  • 13
  • 108
  • 143
2

Change

<a href='fund_view.php?idfund="<? echo $row['idfund']; ?>"'>

to

<a href='fund_view.php?idfund=<? echo $row['idfund']; ?>'>

Also keep in mind that your code is quite unsecure... At least cast the parameter to int before using it:

$aidi = (integer) $_GET['idfund'];
Sergey Eremin
  • 10,994
  • 2
  • 38
  • 44
  • doing the int-casting presumes that it really is an int. while mentioning security is fine, making a blanket "you must turn it into an int" statement is of no use. – Marc B Jul 16 '12 at 14:34
  • a field/parameter/column/whatever named ID _should_ be integer – Sergey Eremin Jul 16 '12 at 14:36
  • 1
    why? perhaps the op's system requires an alphanumeric id, e.g. 'abc001'. like I said, blanket statements are of no use. – Marc B Jul 16 '12 at 14:36
0

Earlier versions of PHP (below 5.4) had an insanely counter-intuitive feature called "magic quotes" which automatically (and silently) escapes all GET/POST strings as if they were going to be used in a MySQL query.

It's relatively simple to reverse, just a headache when you're unaware that such a feature exists.

Solution 1: Turn off magic_quotes with ini_set

Sometimes you won't be able to use ini_set (restrictive host providers), so the following is the next best (and portable) solution that I've used:

NB: function provided on the get_magic_quotes_gpc function page

<?php
    function stripslashes_deep(&$value)
    {
        $value = is_array($value) ?
                    array_map('stripslashes_deep', $value) :
                    stripslashes($value);

        return $value;
    }

    if (get_magic_quotes_gpc())
    {
        stripslashes_deep($_GET);
        stripslashes_deep($_POST);
    }

?> 
Jason Larke
  • 5,289
  • 25
  • 28