Jump to content

Search the Community

Showing results for tags 'csv upload mysqli'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. Hi peeps I have been using mysql commands for most of my php coding, and i've been told it would be wise to move to mysqli im trying to create a csv upload to database page but its just adding blank fields can someone tell me where im going wrong? as my code wont tell me <?php include('header.php'); ?> <!DOCTYPE html> <head> <title>Upload New Numbers files to the database</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body> <form action="importData.php" method="post" enctype="multipart/form-data"> <input type="file" name="uploaded_file"><br> <input type="submit" value="Upload file"> </form> </body> </html> <?php error_reporting(E_ALL); ini_set('display_errors', 1); if (isset($_FILES['uploaded_file'])) { //Make sure the file was sent without errors if ($_FILES['uploaded_file']['error'] == 0) { //connect to the database $mysqli = new mysqli ('localhost','root','','PDNumbers'); if (mysqli_connect_errno()) { die("Mysqli connection failed: ". mysqli_connect_error()); } //gather all the required data from the CSV $file= $_FILES['uploaded_file']['tmp_name']; $handle = fopen($file, "r"); $row= 1; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if ($row == 1) { //skip the first row } else { //csv format like this //$data[0] = mobile number //$data[1] = landline //$data[2] = title //$data[3] = forename //$data[4] = surname //$data[5] = Address1 //$data[6] = Address2 //$data[7] = Address3 //$data[8] = blank field //$data[9] = Town //$data[10] = County //$data[11] = postcode } } } //$import_query = "INSERT IGNORE INTO LepusData (mobile,landline,title,forename,surname,Address1,Address2,Address3,Town,County,postcode) //VALUES ( //'".$data[0]."','".$data[1]."','".$data[2]."','".$data[3]."','".$data[4]."','".$data[5]."','".$data[6]."','".$data[7]."','".$data[8]."','".$data[10]."','".$data[11]."' //)"; $import_query = "INSERT INTO LepusData(mobile) VALUES ('".$data[0]."')"; $result = $mysqli->query($import_query); if ($result) { echo "Success! The file was added into the database"; } else { echo "Error! failed to insert the file"; } // close the mysqli connection $mysqli->close(); } else { echo "Error! The file was not sent!"; } ?> any help is greatly appreciated thanks oh forgot to add, I am ignoring data[9] on purpose, its a blank field
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.