trying to do and upload csv script and hitting an error that doesn't make sense. invalid token. It says my columns don't match my ?,?,?,?,?. 5 columns, 5 ? question marks, what did I miss?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<form enctype="multipart/form-data" method="POST">
<input name="userfile" type="file">
<input type="submit" value="Upload">
<input name="row_name" type="text">
</form>
<?php
$dsn = "mysql:host=$host;port=$port;dbname=$dbname"; //Data Source Name = Mysql
(isset($rowname = $_POST['row_name']));
$db = new PDO($dsn, $db_username, $db_password); //Connect to DB
$do = $db->prepare(
"CREATE TABLE IF NOT EXISTS $username.$rowname (
id INT AUTO_INCREMENT NOT NULL,
list_name varchar(100) NOT NULL,
fname char(60),
lname char(60),
list_email varchar(100),
PRIMARY KEY (id)
)
CHARACTER SET utf8 COLLATE utf8_general_ci
TRUNCATE TABLE $username.$rowname
INSERT INTO $username.$rowname VALUES(?,?,?,?,?)"
);
$csv_file = $_FILES['userfile']['tmp_name'];
if (($handle = fopen($csv_file, "r")) !== FALSE) {
while (($data = fgetcsv($handle)) !== FALSE) {
$do->execute($data);
var_dump($data);}
fclose($handle);}
exit( "Complete!" );
?>
</body>
</html>
error
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /home/wemail1/www/pages/campaign-build.inc.php on line 58
Sample data:
fname, lname, email
joe, schmoe, bogus@bogus.com
mary, lamb, hoe@us.com