Jump to content

[SOLVED] db connect issues


bouwob

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/39579-solved-db-connect-issues/
Share on other sites

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.