Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try to run a query <code>"SET NAMES utf8"</code> before inserting something.</p> <pre><code>mysql_query("SET NAMES utf8"); </code></pre> <p>Also, you do not need to put your <code>mysql_connect()</code> in a loop.</p> <p>Try this code:</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;form action="upload_file_xls.php" method="post" enctype="multipart/form-data"&gt; &lt;input type="file" name="file" id="file" /&gt;&lt;br/&gt; &lt;input type="submit" name="insert" value="Upload"/&gt; &lt;/form&gt; &lt;/body&gt; &lt;?php $link = mysql_connect('localhost', 'root', ''); $db_selected = mysql_select_db('sugoroku01', $link); if (!$db_selected) { die ('Database access error : ' . mysql_error()); } mysql_query("SET NAMES utf8"); mysql_query("SET CHARACTER SET utf8"); if(isset($_POST['insert'])){ if ($_FILES["file"]["error"] &gt; 0) { echo "Error: " . $_FILES["file"]["error"] ; } else{ include 'excel/reader.php'; $excel = new Spreadsheet_Excel_Reader(); $file = $_FILES['file']['tmp_name']; $excel-&gt;read($file); $x=1; while($x&lt;=$excel-&gt;sheets[0]['numRows']) { $number = isset($excel-&gt;sheets[0]['cells'][$x][1]) ? $excel-&gt;sheets[0]['cells'][$x][1] : ''; $province = isset($excel-&gt;sheets[0]['cells'][$x][2]) ? $excel-&gt;sheets[0]['cells'][$x][2] : ''; $city = isset($excel-&gt;sheets[0]['cells'][$x][3]) ? $excel-&gt;sheets[0]['cells'][$x][3] : ''; $alphabet = isset($excel-&gt;sheets[0]['cells'][$x][4]) ? $excel-&gt;sheets[0]['cells'][$x][4] : ''; $query = "INSERT INTO `province_city_tbl`(`province`, `city`, `alphabet`) VALUES ('".$province."', '".$city."', '".$alphabet."') "; mysql_query($query) or die('Error, Feedback insert into database failed'); $x++; } } } ?&gt; &lt;/html&gt; </code></pre>
    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.
    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