Jump to content


Csv File Import To Phpmyadmin Via Php Help

cvs phpmyadmin php import file

  • Please log in to reply
5 replies to this topic

#1 BenardZMEDIA

  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 November 2012 - 01:10 PM

this is the scrip i currently have but i get "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'range,groups,b_m,product_code,desc_1,desc_2,qty,nett_price,goods_value) VALUES (' at line 1"

if (isset($_POST['submit']))

$handle = fopen($_FILES['filename']['tmp_name'], "r");
while(($data = fgetcsv($handle,1000,",")) !==false)

$query = "INSERT INTO sales_orders (ST,date,actual_date,account,branch,customer_name,i_c,invoice_num,category,order_no,order_item,range,groups,b_m,product_code,desc_1,desc_2,qty,nett_price,goods_value) VALUES ('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[9]','$data[10]','$data[11]','$data[12]','$data[13]','$data[14]','$data[15]','$data[16]','$data[17]','$data[18]','$data[19]')";
mysql_query($query) or die(mysql_error());


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo COMPANY_NAME; ?> | Sales Figures Upload Screen</title>

<link href="<?php echo ROOT; ?>css/login.css" type="text/css" rel="stylesheet" />
<link type="text/css" href="<?php echo ROOT; ?>css/start/jquery-ui-1.8.7.custom.css" rel="stylesheet" />
<script type="text/javascript" src="<?php echo ROOT; ?>js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="<?php echo ROOT; ?>js/jquery-ui-1.8.7.custom.min.js"></script>



<div id="box">

<div id="content">

<h1>Sales CSV Update</h1>

<p>Please use a valid CSV file extracted from Exant Exporter.</p>

<form method="post" action="uploadsale.php" enctype="multipart/form-data">
<input type="file" name="filename"/>

<input name="submit" type="hidden"/>

<button tabindex="4" type="submit">Upload Data</button>





<?php mysql_close($connection); ?>

#2 Pikachu2000

  • Staff Alumni
  • I hate everything.
  • 11,384 posts
  • LocationFuture Independent Republic of Texas
  • Age:106

Posted 14 November 2012 - 01:40 PM

'range' is a MySQL reserved word.

Edited by Pikachu2000, 14 November 2012 - 01:41 PM.

"Java" is to "Javascript" about the same as "fun" is to "funeral".

Why $_SERVER['PHP_SELF'] is bad. || Why ORDER BY RAND() is bad || Every problem can be solved with rm -rf *

Random Quote: "

Remember, you're unique. Just like everybody else!

#3 jazzman1

  • Moderators
  • Advanced Member
  • 2,715 posts
  • LocationMississauga, Canada

Posted 14 November 2012 - 01:51 PM

Ha-ha-ha, Pika I suspected the same like you, oped up this site, so start searching "range" and found nothing -> http://msdn.microsof...(v=sql.80).aspx
After your post I saw that I was looking reserved words in MSSQL :happy-04:

@BenardZMEDIA, do you know that phpmyadmin is a not database? Your title is wrong.

#4 BenardZMEDIA

  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 November 2012 - 02:53 PM

i changes it to a different name but i still get the error

i have an excel sheet with column names
ST Date Date (2) A/C BR Customer Name I/C I/C No Cat Order No Order Item Range Group B/M Product Code Description 1 Description 2 Qty Nett Price Goods Value

all am trying to do is upload the csv file into mysql table without having to worry about the column names but still be able to insert data by ignoring the first row and read data row by row with "," as my delimiter.

#5 BenardZMEDIA

  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 November 2012 - 02:55 PM

@ jazzman1 sorry if i got the wrong title this has been bugging me for hours

#6 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 17,836 posts

Posted 14 November 2012 - 03:58 PM

This is the fastest way

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users