Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP CSVImport data
    text
    copied!<p>I Created a file called import.php for PHP that I used to import a csv file. but its not working fine.i have 3 field in database.name id email email got alwyas numeric value 0 and name null.</p> <p>Here is part of the script.</p> <p>Any ideas why it would be being read as a long line?</p> <pre><code> &lt;?php $connect = mysql_connect('localhost','root',''); if (!$connect) { die('Could not &lt;span class="IL_AD" id="IL_AD3"&gt;connect to&lt;/span&gt; &lt;span class="IL_AD" id="IL_AD12"&gt;MySQL&lt;/span&gt;: ' . mysql_error()); } $cid =mysql_select_db('test',$connect); // supply your database name define('CSV_PATH','D:/xampp/htdocs/import/'); // path where your CSV file is located $csv_file = CSV_PATH . "aa.csv"; // Name of your CSV file $csvfile = fopen($csv_file, 'r'); $theData = fgets($csvfile); $i = 0; while (!feof($csvfile)) { $csv_data[] = fgets($csvfile, 1024); $csv_array = explode(",", $csv_data[$i]); $insert_csv = array(); $insert_csv['ID'] = $csv_array[0]; $insert_csv['name'] = $csv_array[1]; $insert_csv['email'] = $csv_array[2]; $query = "INSERT INTO csv(ID,name,email) VALUES('','".$insert_csv['name']."','".$insert_csv['email']."')"; $n=mysql_query($query, $connect ); $i++; } fclose($csvfile); echo "File data successfully imported to database!!"; mysql_close($connect); ?&gt; and this is my input file from where i upload csv file....i got Warning msg and my data base fiel id is created and email value i got 0 and name id null. &lt;html&gt; &lt;body&gt; &lt;form action="impt.php" method="post" enctype="multipart/form-data"&gt; &lt;label for="file"&gt;Filename:&lt;/label&gt; &lt;input type="file" name="file" id="file"&gt;&lt;br&gt; &lt;input type="submit" name="submit" value="Submit"&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

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