djdellux Posted December 15, 2008 Share Posted December 15, 2008 i am having trouble with a specific line of code and have been emersed in my A+ cert over the last 2 wks so any help to bring me back to the world of php would be great heres the rest of the code <?php $dbvoip = sqlite_open('voip.sqlite'); if ($dbvoip == false) { die ('Unable to open database'); } else { echo 'Database created.'; } $dbinfo=file("master.csv"); foreach ($dbinfo as $dbquery) { $data =implode("','",$dbquery); print_r($dbquery); exit; $dbquery = "INSERT INTO voip (C0, number1, number2, type, number3, linetype, c1, dial, c2, date1, date2, date3, c3, c4, anw, DOCUMENTATION, unix, C17) VALUES ($data)"; } sqlite_close($dbvoip) ?> Link to comment https://forums.phpfreaks.com/topic/137035-solved-data-implodedbquery/ Share on other sites More sharing options...
JonnoTheDev Posted December 15, 2008 Share Posted December 15, 2008 You need to print the error Link to comment https://forums.phpfreaks.com/topic/137035-solved-data-implodedbquery/#findComment-715696 Share on other sites More sharing options...
djdellux Posted December 15, 2008 Author Share Posted December 15, 2008 ie print $data ?? Link to comment https://forums.phpfreaks.com/topic/137035-solved-data-implodedbquery/#findComment-715703 Share on other sites More sharing options...
nadeemshafi9 Posted December 15, 2008 Share Posted December 15, 2008 ie print $data ?? data is a string, $dbquery is an array , otherwise it wont work cos $data =implode("','",$dbquery); means take $dbquery and implode it seperated by ',' in to a string Link to comment https://forums.phpfreaks.com/topic/137035-solved-data-implodedbquery/#findComment-715705 Share on other sites More sharing options...
JonnoTheDev Posted December 15, 2008 Share Posted December 15, 2008 No, I mean post the error you are receiving from your code. How can we see what is wrong if you dont explain or post the error. Link to comment https://forums.phpfreaks.com/topic/137035-solved-data-implodedbquery/#findComment-715710 Share on other sites More sharing options...
djdellux Posted December 15, 2008 Author Share Posted December 15, 2008 Warning: implode() [function.implode]: Bad arguments. in c:\program files\Apache\htdocs\csv2.php on line 15 sorry bout that lol Link to comment https://forums.phpfreaks.com/topic/137035-solved-data-implodedbquery/#findComment-715733 Share on other sites More sharing options...
JonnoTheDev Posted December 15, 2008 Share Posted December 15, 2008 implode() takes an array and converts to a string. Is your variable an array? foreach ($dbinfo as $dbquery) { $data =implode("','",$dbquery); print_r($dbquery); Also lose the ' in the implode separator $data = implode(",",$dbquery); Link to comment https://forums.phpfreaks.com/topic/137035-solved-data-implodedbquery/#findComment-715744 Share on other sites More sharing options...
djdellux Posted December 15, 2008 Author Share Posted December 15, 2008 my whole intention is to insert info into the $dbquery variable new code after tweking does it look like this is accomplished <?php $dbvoip = sqlite_open('voip.sqlite'); if ($dbvoip == false) { die ('Unable to open database'); } else { echo 'Database created.'; } $dbinfo=file("master.csv"); foreach ($dbinfo as $dbquery); { // $data =implode(",",$dbquery); $dbquery = "INSERT INTO voip (C0, number1, number2, type, number3, linetype, c1, dial, c2, date1, date2, date3, c3, c4, anw, DOCUMENTATION, unix, C17) VALUES ($dbquery)"; echo($dbquery); } sqlite_close($dbvoip) ?> Link to comment https://forums.phpfreaks.com/topic/137035-solved-data-implodedbquery/#findComment-715798 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.