/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] mysql issues

[code=php]
function querydatabase ($query)
{
$db_host = ‘xxx’;
$db_name = ‘xxx’;
$db_user = ‘xxx’;
$db_pass = ‘xxx’;
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+)(sS+)(s.+)(sS+)(sS)/’,’\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);[/code]

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.

what am I doing wrong

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@SheldonFeb 22.2007 — Why are you connecting every time

it proberly only runs once because it times out after that


try something like
[code=php]
<?php

$db_host = 'xxx';
$db_name = 'xxx';
$db_user = 'xxx';
$db_pass = 'xxx';
mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name);


$fp = fopen('./car.txt','r') or die ("it wont open");
echo("<ul>");
while (!feof($fp) )
{
$line = fgets($fp);
$fred = preg_replace('/(S+)(sS+)(s.+)(sS+)(sS)/','\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])."')";
mysql_query($query) or die ("Your error is...".mysql_error());
echo("<li>Success: ". trim($line)."</li>"."rn");
}

fclose($fp);
echo("</ul>");
?>
[/code]
×

Success!

Help @DARTHTAMPON spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.12,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...