dizel247 Posted November 22, 2007 Share Posted November 22, 2007 Hello, I am trying a very simple csv import to mysql. When I import the file, it imports blanks. After my search, I realize my page doesn't pass actual path of the file, it passes just file name. When I manually add the path of the file it imports with no problem. Can some one point me to the right direction. Thanks in advance. Roman Code Bellow: page1.php <form action="page2.php" method="post" name="form1" id="form1"> <table border="0" align="center" cellpadding="5" class="nugget"> <tr> <td colspan="2" class="topheader"><div align="center"><span class="lbl">Rate Load Wizard</span></div></td> </tr> <tr> <td>Report Name:</td> <td><label> <select name="report_name" id="report_name"> <option value="">Select Report Name</option> <?php do { ?> <option value="<?php echo $row_rsAccountName['report_id']?>"><?php echo $row_rsAccountName['report_name']?></option> <?php } while ($row_rsAccountName = mysql_fetch_assoc($rsAccountName)); $rows = mysql_num_rows($rsAccountName); if($rows > 0) { mysql_data_seek($rsAccountName, 0); $row_rsAccountName = mysql_fetch_assoc($rsAccountName); } ?> </select> </label></td> </tr> <tr> <td>Lodaing Data For:</td> <td><table width="200"> <tr> <td><label> <input type="radio" name="account_type" value="1" id="acc_data_type_0" /> Customers</label></td> </tr> <tr> <td><label> <input type="radio" name="account_type" value="2" id="acc_data_type_1" /> Vendors</label></td> </tr> </table></td> </tr> <tr> <td>Select File to load:</td> <td><label> <input name="userfile" type="file" class="sm" id="userfile" /> </label> </td> </tr> <tr> <td> </td> <td><label> <div align="right"> <input type="submit" name="submit" id="submit" value="submit" /> </div> </label></td> </tr> </table> </form> Page2.php <?php print_r($_POST); $path = $_POST['userfile']; $fcontents = file ("$path"); echo $path; for($i=0; $i<sizeof($fcontents); $i++) { $line = trim($fcontents[$i]); $arr = explode(",", $line); #if your data is comma separated # instead of tab separated, # change the '\t' above to ',' $reportname=$_POST['report_name']; $account_type=$_POST['account_type']; $sql = "insert into tb_accounts (carrier_code, minutes, profit, revenue, cost, report_id, account_type) values ('$arr[0]', '$arr[1]', '$arr[2]', '$arr[3]', '$arr[4]', '$reportname', '$account_type')"; mysql_query($sql); echo $sql ."<br>\n"; if(mysql_error()) { echo mysql_error() ."<br>\n"; } } ?> Debug: Array ( [report_name] => 2 [account_type] => 1 [userfile] => test.csv [submit] => submit ) test.csv insert into tb_accounts (carrier_code, minutes, profit, revenue, cost, report_id, account_type) values ('', '', '', '', '', '2', '1') Link to comment https://forums.phpfreaks.com/topic/78460-problem-with-importing-cvs-to-mysql/ Share on other sites More sharing options...
mithpower Posted November 23, 2007 Share Posted November 23, 2007 Do you have your register_globals enabled in your php.ini file? That would be the problem, you might have to declare the variable $var = $_POST['fieldname']; Mith Link to comment https://forums.phpfreaks.com/topic/78460-problem-with-importing-cvs-to-mysql/#findComment-397499 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.