Importing into MYSQL Database

Reply

Join Date: May 2009
Posts: 8
Reputation: niche1 is an unknown quantity at this point 
Solved Threads: 0
niche1 niche1 is offline Offline
Newbie Poster

Importing into MYSQL Database

 
0
  #1
Oct 19th, 2009
I need to import TEST.TXT (located in the same directory as my script

It has 1 Record: "6","Lunch","234"

Iget this error message: Warning: mysqli_close() expects exactly 1 parameter, 0 given in C:\wamp\www\test\import.php on line 19

Why?

Heres my script:

  1. <?php
  2. // Connect to the MySQL server and select the corporate database
  3. $mysqli = new mysqli("localhost","user,"password,"test");
  4. // Open and parse the test.txt file
  5. $fh = fopen("test.txt", "r");
  6. while ($line = fgetcsv($fh, 1000, ","))
  7. {
  8. $id = $line[0];
  9. $item = $line[1];
  10. $price = $line[2];
  11.  
  12. // Insert the data into the sales table
  13. $query = "INSERT INTO example SET id='$id',
  14. item='$item', price='$price'";
  15.  
  16. $result = $mysqli->query($query);
  17. }
  18. fclose($fh);
  19. mysqli_close();
  20. ?>
Last edited by peter_budo; Oct 22nd, 2009 at 2:18 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 224
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey
 
0
  #2
Oct 19th, 2009
Originally Posted by niche1 View Post
I need to import TEST.TXT (located in the same directory as my script

It has 1 Record: "6","Lunch","234"

Iget this error message: Warning: mysqli_close() expects exactly 1 parameter, 0 given in C:\wamp\www\test\import.php on line 19

Why?

Heres my script:
  1. <?php
  2. // Connect to the MySQL server and select the corporate database
  3. $mysqli = new mysqli("localhost","user,"password,"test");
  4. // Open and parse the test.txt file
  5. $fh = fopen("test.txt", "r");
  6. while ($line = fgetcsv($fh, 1000, ","))
  7. {
  8. $id = $line[0];
  9. $item = $line[1];
  10. $price = $line[2];
  11.  
  12. // Insert the data into the sales table
  13. $query = "INSERT INTO example SET id='$id',
  14. item='$item', price='$price'";
  15.  
  16. $result = $mysqli->query($query);
  17. }
  18. fclose($fh);
  19. mysqli_close();
  20. ?>
  1. $mysqli->close();
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 8
Reputation: niche1 is an unknown quantity at this point 
Solved Threads: 0
niche1 niche1 is offline Offline
Newbie Poster
 
0
  #3
Oct 19th, 2009
Wow!

Thank You very much!
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC