-4

I recently updated the server on which I work. I have got an error:

"Warning: array_flip() expects parameter 1 to be array, null given in..."

Does someone know how to fix it?

Here is a part of PHP code:

function redirectWrongDep($url) { 
    $deps = @getDepsByIdUrl($url); 
    $depsFlip = array_flip($deps); 
    if ($_GET['dep'] && !in_array($_GET['dep'], $depsFlip)) { header('Location:'.URL); 
        exit(); 
    } 
} 
function getDepsByIdUrl($url) { 
    $sql = "SELECT ws_flash_departement.nom,ws_flash_departement.id_departement FROM ws_flash_departement WHERE ws_flash_departement.no_resultats != 0 AND ws_flash_departement.id_departement IN (SELECT url_departement.id_departement FROM url_departement WHERE url_departement.id_url=" . $url . ") ORDER BY nom ASC"; 
    $result = mysql_query($sql); 
    while ($row = mysql_fetch_assoc($result)) { 
        $deps[$row["id_departement"]]=utf8_encode($row["nom"]); 
    } 
    mysql_free_result($result); 
    return $deps; 
 } 
brasofilo
  • 25,496
  • 15
  • 91
  • 179
Pureandfast
  • 29
  • 4
  • 7

3 Answers3

1

most likely you updated to an server where magic quotes is set on off

This id because something is returning the value false or not returning true or 1 so debug the code .you are not suplling anything too the array_flip() you have to supply array

example:

$arr = array("a" => 3, "b" => 1, "c" => 2);
$arr = array_flip($arr);
print_r($arr);
NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
Dirk Zaal
  • 225
  • 2
  • 8
0

array_flip takes an array as first parameter and you give nothing...

PS: Maybe with some lines of code, I could give you a more precise answer

Antoine
  • 2,785
  • 1
  • 16
  • 23
  • Here is a part of PHP code : function redirectWrongDep($url) { $deps = @getDepsByIdUrl($url); $depsFlip = array_flip($deps); if ($_GET['dep'] && !in_array($_GET['dep'], $depsFlip)) { header('Location:'.URL); exit(); } } – Pureandfast Jun 06 '12 at 09:12
  • A second part : function getDepsByIdUrl($url) { $sql = "SELECT ws_flash_departement.nom,ws_flash_departement.id_departement FROM ws_flash_departement WHERE ws_flash_departement.no_resultats != 0 AND ws_flash_departement.id_departement IN (SELECT url_departement.id_departement FROM url_departement WHERE url_departement.id_url=" . $url . ") ORDER BY nom ASC"; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $deps[$row["id_departement"]]=utf8_encode($row["nom"]); } mysql_free_result($result); return $deps; } – Pureandfast Jun 06 '12 at 09:13
  • What's the value returned by getDepsByIdUrl ? – Antoine Jun 06 '12 at 10:06
  • This function returns an array of departments (it is a french project). The french Departments are from 1 to 95. – Pureandfast Jun 06 '12 at 10:46
  • I mean does it return what you are expecting ? Did you print_r this array ? – Antoine Jun 06 '12 at 11:20
0

Check this manual:

http://php.net/manual/en/function.array-flip.php

Eg.

$trans = array("a" => 1, "b" => 1, "c" => 2);
$trans = array_flip($trans);
print_r($trans);
sephoy08
  • 1,104
  • 7
  • 16