php - failed to import the csv file to mysql -
plzz me fix errors in following code.. couldn't read php code. how can make it? want show status of connection when closes.
<table width="600" style="margin:115px auto; background:#f8f8f8; border:1px solid #eee; padding:20px 0 25px 0;"> <form action="<?php echo $_server["php_self"]; ?>" method="post" enctype="multipart/form-data"> <tr><td colspan="2" style="font:bold 15px arial; text-align:center; padding:0 0 5px 0;">browse , import excel file </td></tr> <tr> <td width="50%" style="font:bold 12px tahoma, arial, sans-serif; text-align:right; border-bottom:1px solid #eee; padding:5px 10px 5px 0px; border-right:1px solid #eee;">select file</td> <td width="50%" style="border-bottom:1px solid #eee; padding:5px;"><input type="file" name="file" id="file" /></td> </tr> <tr> <td style="font:bold 12px tahoma, arial, sans-serif; text-align:right; padding:5px 10px 5px 0px; border-right:1px solid #eee;">import</td> <td width="50%" style=" padding:5px;"><input type="submit" value="submit" /></td> </tr> </form> </table> <?php if(isset($_post['submit'])) { echo connection_status(); $connect = mysql_connect('localhost:8080','root',''); if (!$connect) { die('could not connect mysql: ' . mysql_error()); } $cid =mysql_select_db('ts_order_track',$connect); $file = $_files['file']['tmp_name']; if (($getfile = fopen($file, "r")) != false) { echo "csvs open"; $data = fgetcsv($getfile, 3000, ","); echo "csvs data reading"; while (($data = fgetcsv($getfile, 3000, ",")) != false) { $num = count($data); ($c=0; $c < $num; $c++) { $result = $data; $str = implode(",", $result); $slice = explode(",", $str); $col1 = $slice[0]; $col2 = $slice[1]; $col3 = $slice[2]; $col4 = $slice[3]; $col5 = $slice[4]; $col6 = $slice[5]; $col7 = $slice[6]; $col8 = $slice[7]; $col9 = $slice[8]; $col10 = $slice[9]; $col11 = $slice[10]; $col12 = $slice[11]; $col13 = $slice[12]; $col14 = $slice[13]; $col15 = $slice[14]; $col16 = $slice[15]; $col17 = $slice[16]; $col18 = $slice[17]; $col19 = $slice[18]; $col20 = $slice[19]; $col21 = $slice[20]; $col22 = $slice[21]; $col23 = $slice[22]; $col24 = $slice[23]; $col25 = $slice[24]; $col26 = $slice[25]; $col27 = $slice[26]; $col28 = $slice[27]; $col29 = $slice[28]; $col30 = $slice[29]; $col31 = $slice[30]; $col32 = $slice[31]; $col33 = $slice[32]; $col34 = $slice[33]; $col35 = $slice[34]; $col36 = $slice[35]; $col37 = $slice[36]; $sql = "insert tsd_orders(order_id, customer_id, firstname, lastname, email, telephone, mobile, shipping_firstname, shipping_lastname, shipping_mobile, shipping_address_1, shipping_address_2, shipping_city, shipping_zone, shipping_postcode, shipping_country, shipping_method, payment_method, payment_code, weight, date_added, date_modified, import_order_id, sub_total, shipping_charges, tax_charges, total, order_status, courier, awb_code, coupon_amount, coupon_code, product_name, product_sku, product_model, product_quantity, product_price) values('".$col1."','".$col2."','".$col3."','".$col4."','".$col5."','".$col6."','".$col7."','".$col8."','".$col9."','".$col10."','".$col11."','".$col12."','".$col13."','".$col14."','".$col15."','".$col16."','".$col17."','".$col18."','".$col19."','".$col20."','".$col21."','".$col22."','".$col23."','".$col24."','".$col25."','".$col26."','".$col27."','".$col28."','".$col29."','".$col30."','".$col31."','".$col32."','".$col33."','".$col34."','".$col35."','".$col36."','".$col37."')"; $s=mysql_query($sql, $connect ); echo "csvs data reading"; } } echo "file data imported database!!"; mysql_close ( $connect ); echo connection_status(); }} ?>
it gives these errors: ** warning: mysql_connect(): mysql server has gone away in c:\xampp\htdocs\trendspry.php on line 22
warning: mysql_connect(): error while reading greeting packet. pid=1824 in c:\xampp\htdocs\trendspry.php on line 22
warning: mysql_connect(): mysql server has gone away in c:\xampp\htdocs\trendspry.php on line 22
fatal error: maximum execution time of 30 seconds exceeded in c:\xampp\htdocs\trendspry.php on line 22**
i m using xampp.. server localhost , port 8080. helping me.
you missing name attribute here
<input type="submit" value="submit" />
changed
<input type="submit" value="submit" name="submit"/>
one more thing. dont use mysql_* deprecated. read here
updated
try this
$connect = mysql_connect('localhost:8080','root','');
change to
$connect = mysql_connect('localhost','root','');
Comments
Post a Comment