bouwob Posted February 22, 2007 Share Posted February 22, 2007 function querydatabase ($query) { $db_host = 'localhost'; $db_name = 'localhost'; $db_user = 'localhost'; $db_pass = 'localhost'; mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name); $result = mysql_query($query) or die(mysql_error()); mysql_close(); return $result; } $fp = fopen('./car.txt','r') or die ("it wont open"); while (!feof($fp) ) { $line = fgets($fp); $fred = preg_replace('/(\S+)(\s\S+)(\s.+)(\s\S+)(\s\S)/','\\1,\\2,\\3,\\4,\\5',$line); $pieces = explode(",", $fred); $query = "insert into cars(year, make, model, zeroToSixty, querterMile) values ('".trim($pieces[0])."','".trim($pieces[1])."','".trim($pieces[2])."',".trim($pieces[3]).",".trim($pieces[4]).")"; echo $query; $result = querydatabase ($query) or die(echo mysql_error()); } fclose($fp); runs once then stops. Never inserts data. I know the query is good so I must have something wrong somewhere. Are the dies in the right place? I am recieveing no errors. I know the query is good, what am I doing wrong Quote Link to comment Share on other sites More sharing options...
skali Posted February 22, 2007 Share Posted February 22, 2007 try setting. ini_set('error_reporting', E_ALL); Quote Link to comment Share on other sites More sharing options...
bouwob Posted February 22, 2007 Author Share Posted February 22, 2007 ini_set('error_reporting', E_ALL); $fp = fopen('./car.txt','r') or die ("it wont open"); while (!feof($fp) ) { $line = fgets($fp); $fred = preg_replace('/(\S+)(\s\S+)(\s.+)(\s\S+)(\s\S)/','\\1,\\2,\\3,\\4,\\5',$line); $pieces = explode(",", $fred); echo $pieces[0].",".$pieces[1].",".$pieces[2].",".$pieces[3].",".$pieces[4]; $query = "insert into cars(year, make, model, zeroToSixty, querterMile) values ('".trim($pieces[0])."','".trim($pieces[1])."','".trim($pieces[2])."',".trim($pieces[3]).",".trim($pieces[4]).")"; echo $query; $result = querydatabase ($query) or die(echo mysql_error()); } fclose($fp); that seems to just take the text away? How should it be set? Quote Link to comment Share on other sites More sharing options...
bouwob Posted February 22, 2007 Author Share Posted February 22, 2007 /bump Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 22, 2007 Share Posted February 22, 2007 You still get no errors? Are you actually connecting to the db? Quote Link to comment Share on other sites More sharing options...
bouwob Posted February 22, 2007 Author Share Posted February 22, 2007 You still get no errors? Are you actually connecting to the db? I honestly have no idea. The page wont spit out anything. ran it in shell as well as web. no luck with either. How can I tell if I connect? I thought the die took care of that. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 22, 2007 Share Posted February 22, 2007 instead of: ini_set('error_reporting', E_ALL); do: ini_set('display_errors', 1); error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.