Search the Community
Showing results for tags 'pdo import table database'.
-
Hi Everyone I'm currently trying to learn PHP whilst writing my own custom control panel I had a working import csv page but I got told its not really good to use mysql_* anymore, so I've started again with trying to do it with pdo, but i think I'm well over my head with this one, my page says is successfully uploaded but there is nothing in the Leads table I created so its not putting the data into the table. here's my code so far <?php $used=0; error_reporting(E_ALL); ini_set('display_errors', '1'); if (isset($_POST['submit'])) { require "database/pdo_connection.php"; //upload file if (is_uploaded_file($_FILES['fileName']['tmp_name'])) { echo "<h1>" . "File " . $_FILES['fileName']['name'] . " uploaded Successfully." . "</h1>"; } $filename = $_FILES['fileName']['name']; //Now Lets import the file to the database/connection $handle = fopen($_FILES['fileName']['tmp_name'],"r"); $import=$pdo_connection->prepare( "INSERT IGNORE into Leads(number,date,used,fileName) values(?,?,?,?)" ); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $import->bindParam(1, $data[0], PDO::PARAM_STR); $import->bindParam(2, $data[1], PDO::PARAM_STR); $import->bindParam(3, $used, PDO::PARAM_INT); $import->bindParam(4, $filename, PDO::PARAM_INT); $import->execute(); } fclose($handle); } else { print "<div id='box'>"; print "Upload new csv by browsing to file and clicking on Upload<br/>\n"; print "<form enctype='multipart/form-data' action='Leads2.php' method='post'>"; print "File name to import:<br/>\n"; print "<input id='test' size='10' type='file' name='fileName' ><br/>\n"; print "<input type='submit' name='submit' value='Upload'></form>"; print "</div>"; } ?> Thanks in advance for any help given