0

I'm using a very simple code to extract data from a MySQL DB to a CSV file. The code didn't provide the result I expected so I made the code including the query in the CSV file. In a fist part of the code seemes that the variable containing the query result doesn't actually contain any value, but in another part of the code the variable contains the correct value. In short, the same variable seems to contain two values in different part of the code.

$sql="SELECT destinazione AS dest,ndc AS n FROM npitz";
$query = mysql_query($sql);

$q="ERROR";
while($row = mysql_fetch_array($query)) {
$query="DELETE FROM npitz_reduced_tmp WHERE 
        destinazione='".$row['dest']."' AND 
        ndc LIKE CONCAT('".$row['n']."','%') AND 
        ndc NOT LIKE '".$row['n']."'";
if($row['n']='77') $q=$query."   -   ".$row['n'];
mysql_query($query);
}

The variable $row['n'] should contain the result of the SQL query. After the while loop the variable $q is:

DELETE FROM npitz_reduced_tmp WHERE destinazione='UNITED STATES' AND ndc LIKE CONCAT('','%') AND ndc NOT LIKE ''   -   77

The question is: if in the IF statement the value of $row['n'] is '77' why it isn't the same in the $query variable assignment?

  • 1
    `$row['n']='77'` is setting the value of `$row['n']` equal to '77' - `=` sets values, it doesn't compare them – Derek Pollard Feb 06 '19 at 17:47
  • 1
    while you are at it (hands in code), you should really drop the `mysql_` api ... it is deprecated and your are barring yourself from many useful/necessary security characteristics of a modern php with either `mysqli` or `PDO` api's and drivers. – YvesLeBorg Feb 06 '19 at 17:50

1 Answers1

3

You probably should use == instead of = in the if statement

Serge Ageyev
  • 437
  • 3
  • 8