-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
26.2k15 gold badges96 silver badges189 bronze badges
asked Jun 6, 2012 at 8:51
1
  • You are trying to flip a NULL Commented Sep 5, 2012 at 8:23

3 Answers 3

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я
57.3k23 gold badges130 silver badges148 bronze badges
answered Mar 10, 2013 at 0:57
Sign up to request clarification or add additional context in comments.

Comments

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

answered Jun 6, 2012 at 8:56

5 Comments

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(); } }
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; }
What's the value returned by getDepsByIdUrl ?
This function returns an array of departments (it is a french project). The french Departments are from 1 to 95.
I mean does it return what you are expecting ? Did you print_r this array ?
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);
answered Jun 6, 2012 at 8:58

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.