title: Inserting data and/or Updating database using CSV
body: <p><br></p>
  
  <p>So I've been working on this for some time, but i cant seem to figure out how to get it to work.</p>
  
  <p>I want to update the prices of a product in the database if the product id is there, if it's not there i want it to insert the new id and it's prices.</p>
  
  <p>Using the code below it updates the database, however it does not insert anything if the id is not there.</p>
  
  <p>Any clues on what's gone wrong?</p>
  
  <p>With thanks <br>
  Jim</p>
  
  <p>EDIT</p>
  
  <p>This works for me:</p>
  
  <pre><code>$count = mysql_num_rows(mysql_query("SELECT id FROM products WHERE id = '$id'"));
  
  
  
              if ($count == 1){
  
              mysql_query("UPDATE products SET price='$price',ordprice='$ordprice' WHERE id='$id'");
  
              }elseif($count == 0){
  
              mysql_query("INSERT INTO products (id,price,ordprice) VALUES ('$id','$price','$ordprice')");
              }
  </code></pre>
  
  <p>/EDIT</p>
  
  <pre><code>if(isset($_POST['submit']))
      {
          $file = $_FILES['file']['tmp_name'];
  
          $handle = fopen($file,"r");
          while(($fileop = fgetcsv($handle,10000,";")) !== false)
          {
              $id = $fileop[0];
              $price = $fileop[1];
              $ordprice = $fileop[2];
  
  
              $count = mysql_num_rows(mysql_query("SELECT id FROM products WHERE id = '$id'"));
  
  
  
              if ($count = $id){
  
              mysql_query("UPDATE products SET price='$price',ordprice='$ordprice' WHERE id='$id'");
  
              }elseif($id != $count){
  
              mysql_query("INSERT INTO products (id,price,ordprice) VALUES ('$id','$price','$ordprice')");
              }
  </code></pre>