/    Sign up×
Community /Pin to ProfileBookmark

Using Addslashes with Implode

Hi

I need to use the addslashes function in every returned field inside a foreach after a file data reading.

So my query will not faill

How it can be done ?

Thank´s in advance

[code=php]
foreach($data as $line) {
$fields = explode(‘&’, $line);
$query = “INSERT INTO table “;
$query .= “(num, name, audit, port, and, movdate);
$query .= ” VALUES (‘”. implode(“‘,'”, $fields) . “‘)”;
echo “<BR>query: “.$query;
//$newFields = implode(“‘,'”, $fields);
}
[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyFeb 14.2006 — have you tried something like this:[code=php]foreach($data as $line) {
$fields = explode('&', $line);
$query = "INSERT INTO table ";
$query .= "(num, name, audit, port, and, movdate)";
$query .= " VALUES ('". implode("','", addslashes($fields)) . "')";
echo "<BR>query: ".$query;
//$newFields = implode("','", $fields);
} [/code]
btw, I also added a " at the end of the second query line that was missing
Copy linkTweet thisAlerts:
@amrigoauthorFeb 15.2006 — thank´s a lot now it is working
×

Success!

Help @amrigo 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...