简体   繁体   中英

Insert array data to mysql table

How can I insert array data from web page to mysql table using below code. actually i want to import data from xls/csv/xml files to web page then want to insert to mysql table. like the tutorial from this link: http://www.ibm.com/developerworks/library/os-phpexcel/ .

 <html> <body> These records have been added to the database: <table> <tr> <th>First</th> <th>Middle</th> <th>Last</th> <th>Email</th> </tr> <?php foreach( $data as $row ) { ?> <tr> <td><?php echo( $row['first'] ); ?></td>< <td><?php echo( $row['middle'] ); ?></td>< <td><?php echo( $row['last'] ); ?></td>< <td><?php echo( $row['email'] ); ?></td>< </tr> <?php } ?> </table> Click <a href="list.php">here</a> for the entire table. </body> </html>

$columns = implode(", ",array_keys($row));
$escaped_values = array_map('mysql_real_escape_string', array_values($insData));
$values  = implode(", ", $escaped_values);
$sql = "INSERT INTO `table`($columns) VALUES ($values)";
<?php foreach( $data as $row ) { 
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
}
?>
<?php foreach( $data as $row ) { 
$sql= "INSERT INTO table_name (`first`, `middle`, `last`,`email`)VALUES (".$row['first'].", ".$row['middle'].", ".$row['last'].",".$row['email'].")";
}
$query = mysql_query($sql);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM