By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,996 Members | 892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,996 IT Pros & Developers. It's quick & easy.

Parse error: syntax error, unexpected T_STRING in C:\wamp\www\upl.php on line 16

P: 2
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con = mysql_connect("localhost","root","");
  3. if (!$con)
  4. {
  5.   die('Failed to connect to server: ' . mysql_error());
  6. }
  7. mysql_select_db("db1", $con);
  8.  
  9. $row = 1;
  10. if (($handle = fopen("contacts.csv", "r")) !== FALSE) {
  11.     while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
  12.         $num = count($data);
  13.         echo "<p> $num fields in line $row: </p>\n";
  14.         $row++;
  15.         for ($c=0; $c < $num; $c++) {
  16.             $query = "INSERT INTO backup ("firstname","number") VALUES ("$data[$c]")";
  17.             mysql_query($query)
  18.         }
  19.     }
  20.  
  21.  //   fclose($handle);
  22. ?>
this is a simple code to parse a csv file and upload details into database in mysql using wamp server. it doesn work with parse error being the reason i think. help plsss
Jan 28 '12 #1
Share this Question
Share on Google+
3 Replies


Rabbit
Expert Mod 10K+
P: 12,350
It's probably your INSERT statement. You have quotes in the field list that shouldn't be there and you have only one value in the value list when you specified two columns.
Jan 29 '12 #2

Dormilich
Expert Mod 5K+
P: 8,639
and please do not cross-post your question in different forums. thatís impolite towards the people answering your question.
Jan 29 '12 #3

P: 2
@dormilich: yes sir i got that! will follow it.. thank you.
Jan 29 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.