Note that there are some explanatory texts on larger screens.

plurals
  1. POError reading a CSV file
    primarykey
    data
    text
    <p>I am very new PHP. Can some please solve my problem?</p> <p>The following code works absolutely fine when i tried to execute using xampp in windows. But it dosen't work on Ubuntu when i try executing through ssh terminal. </p> <p>Following is the php warning. but when i tried it on windows it works fine for all the records in CSV (it gives me insert or update statement for each record in the CSV)</p> <blockquote> <p>PHP Warning: feof() expects parameter 1 to be resource, boolean given in /home/myetexts/Documents/codes/Pearson/test2.php on line 8<br> PHP Warning: fgetcsv() expects parameter 1 to be resource, boolean given in /home/myetexts/Documents/codes/Pearson/test2.php on line 9</p> </blockquote> <pre><code>&lt;?php ini_set('max_execution_time', 10000); $file = fopen('NZ_Price_list.csv', 'r'); $count = 0; $con=mysql_connect("localhost","root",""); mysql_select_db('newlocalabc'); while(!feof($file)){ $record = fgetcsv($file); if(!empty($record[0])){ // echo 'ISBN: '.$record[0].'&lt;br /&gt;'; $price =round(($record[11])/0.85,2); if($record[3]== "Higher Education" || $record[3] == "Vocational Education"){ $price =round((($record[11])/0.85)/0.97,2); } $sql = 'SELECT * FROM `products` WHERE `isbn` = '.$record[0]; $result = mysql_query($sql); if(mysql_num_rows($result)){ $data = mysql_fetch_object($result); $nsql = "UPDATE `products` SET `price` = '".$price."', `cover` = 'pics/cover4/".$record[0].".jpg', `cover_big` = 'pics/cover4/".$record[0].".jpg' WHERE `products`.`isbn` = ".$record[0].";"; }else{ $nsql = "INSERT INTO `products` (`id`, `isbn`, `title`, `publisher_id`, `description`, `supplier_id`, `price`, `author`, `cover`, `cover_big`, `status_id`, `timestamp`) VALUES (NULL, '".$record[0]."', '".addslashes($record[1])."', '7','Not Available', '72', '".$price."', '".$record[2]."', 'pics/cover4/".$record[0].".jpg', 'pics/cover4/".$record[0].".jpg', '0',CURRENT_TIMESTAMP);"; } echo $nsql.'&lt;br /&gt;'; //echo $price.'&lt;br /&gt;'; //echo '&lt;pre&gt;'; print_r($record);exit; } unset($record); $count++; } fclose($file); ?&gt; </code></pre> <p>Hoping to hear back from some one soon.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload