PHP - adding a string to a variable (array) CSV --> MySQL -


i have problem thats baffling mind, i'm unable add string gradually loaded csv file array (through while loop) after writes database.

the code runs, echoes fact has written database, nothing happens, when remove string writes database fine.

the syntax should $variable = 'string' . $csvvalue; won't write database when case, when is: $variable = $csvvalue;

here code:

<?php // script insert data csv-file ad information in mysql database.  // connect database  $connect = mysqli_connect("localhost","root","password","dbname");   if(!$connect){    die('could not <span id="il_ad1" class="il_ad">     connect to</span> mysql: ' . mysql_error()); }  // charset mysqli_query($connect, "set names 'utf8'");  // file path define('csv_path','/home/administrator/desktop/');   $csvname = csv_path . "ansattinfo.csv"; // name of csv-file $csvfile = fopen($csvname, 'r'); $thedata = fgets($csvfile); $i = 0;  while(!feof($csvfile)){      $csv_data[] = fgets($csvfile, 2048);     $csv_array = explode(",", $csv_data[$i]);     $insert_csv = array();     $insert_csv['samaccountname'] = $csv_array[0];     $insert_csv['displayname'] = $csv_array[1];     $insert_csv['employeenumber'] = $csv_array[2];     $insert_csv['mail'] = $csv_array[3];     $insert_csv['company'] = $csv_array[4];     $footer = str_replace(' ', '_', $insert_csv['company']);     //$footer = '@' . str_replace(' ', '_', $insert_csv['company']);      $query = "insert playsms_tblusertest (status, username, enable_webservices, webservices_ip, name, mobile, email, footer, country, datetime_timezone, language_module, fwd_to_mobile, send_as_unicode)         values(             3,             ".$insert_csv['samaccountname'].",             1,             '*.*.*.*',             ".$insert_csv['displayname'].",             ".$insert_csv['employeenumber'].",             ".$insert_csv['mail'].",             ".$footer.",             137,             '+0100',             'nb_no',             1,             1              ) on duplicate key         update name = $insert_csv[displayname], mobile = $insert_csv[employeenumber], email = $insert_csv[mail], footer = $footer";     mysqli_query($connect, $query);     $i++; }  fclose($csvfile);  echo "csv imported user-table! \n";  mysqli_close($connect); // closing connection   ?> 

what want here add string infront of $footer value, @ groupname of contact group, '@' indicator of being group.

in csv file company name not have '@' infront of it, want add. this:

$footer = '@' . str_replace(' ', '_', $insert_csv['company']); 

this not give syntax errors, nothing gets written database.

does have suggestion on solution here?

cheers help.

if field footer in database of "string-type", have fill string:

/* ... */             ".$insert_csv['employeenumber'].",             ".$insert_csv['mail'].",             '".$footer."',             137,             '+0100',             'nb_no',             1,             1              ) on duplicate key         update name = $insert_csv[displayname], mobile = $insert_csv[employeenumber], email = $insert_csv[mail], footer = '$footer'"; /* ... */ 

and declare string in mysql-query have put in between quotes shown above $footer value.

i think got same error multiple times in query: example $insert_csv['mail'] string too, guess.

hint: if used kind of error-handling, have seen there mysql-error (since using pdo don't know how works in mysqli).


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -