PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
vincenzobar
Forum Commoner
Posts: 95 Joined: Wed Nov 02, 2005 9:57 am
Post
by vincenzobar » Wed Nov 09, 2005 1:59 pm
now i am running into a problem with 's
when i do a fetch_rows and then go to move info to anothe DB it doesn't take the rows that contain words like America's
Here is the code
Code: Select all
$move = array();
$f_move = array();
if(in_array($p_id, $DB_IDList)) {
$db_row = mysql_fetch_row($all_rows);
$move[] = "'', "."'".implode("', '", $db_row)."'";
$f_move[] = "(".implode(', ', $move). ")";
$moved = implode(", ", $f_move);
print $moved;
$archive = 'INSERT INTO archive_rateplan VALUES '.$moved.'';
mysql_query($archive) or die(mysql_error());
mysql_query($delete) or die(mysql_error());
}
Where do i or how do i do a addslashes? i triedvarious places but non seemed to work
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Wed Nov 09, 2005 2:30 pm
try mysql_real_escape_string() on the input variable
vincenzobar
Forum Commoner
Posts: 95 Joined: Wed Nov 02, 2005 9:57 am
Post
by vincenzobar » Wed Nov 09, 2005 2:44 pm
everything but the last call is an array for implode to work and if i attach it to the last call it \ all ' and that won't work!!
Arg it's the last step
scheit!!!!!!!!!!!!!!!!!!!!!!!
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Wed Nov 09, 2005 2:48 pm
Did you try this?
Code: Select all
$move = array();
$f_move = array();
if(in_array($p_id, $DB_IDList)) {
$db_row = mysql_fetch_row($all_rows);
$move[] = "'', "."'".implode("', '", $db_row)."'";
$f_move[] = "(".implode(', ', $move). ")";
$moved = implode(", ", $f_move);
print $moved;
$archive = 'INSERT INTO archive_rateplan VALUES '.mysql_real_escape_string($moved).'';
mysql_query($archive) or die(mysql_error());
mysql_query($delete) or die(mysql_error());
}
EDIT: NVM this is wrong... I hang on a minute.
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Wed Nov 09, 2005 2:51 pm
Maybe this?
Code: Select all
$move = array();
$f_move = array();
if(in_array($p_id, $DB_IDList)) {
$db_row = mysql_fetch_row($all_rows);
$move[] = "'', "."'".implode("', '", mysql_real_escape_string($db_row))."'";
$f_move[] = "(".implode(', ', $move). ")";
$moved = implode(", ", $f_move);
print $moved;
$archive = 'INSERT INTO archive_rateplan VALUES '.$moved.'';
mysql_query($archive) or die(mysql_error());
mysql_query($delete) or die(mysql_error());
}
vincenzobar
Forum Commoner
Posts: 95 Joined: Wed Nov 02, 2005 9:57 am
Post
by vincenzobar » Wed Nov 09, 2005 3:42 pm
tried that this is the error
mysql_real_escape_string() expects parameter 1 to be string, array given...
everything in there is an array except the last which makes everything \'
there has to be a way around this!!!
Jenk
DevNet Master
Posts: 3587 Joined: Mon Sep 19, 2005 6:24 am
Location: London
Post
by Jenk » Wed Nov 09, 2005 4:09 pm
You are imploding twice on a one dimensional array?
Anyway..
Code: Select all
array_map('mysql_real_escape_string', $db_row);
vincenzobar
Forum Commoner
Posts: 95 Joined: Wed Nov 02, 2005 9:57 am
Post
by vincenzobar » Wed Nov 09, 2005 4:12 pm
where does that go and how would you implode it otherwise??
it needs to look like this
('asd', 'asd'), (...), (...)
vincenzobar
Forum Commoner
Posts: 95 Joined: Wed Nov 02, 2005 9:57 am
Post
by vincenzobar » Wed Nov 09, 2005 4:18 pm
i did this
Code: Select all
$move = array();
$f_move = array();
if(in_array($p_id, $DB_IDList)) {
$db_row = mysql_fetch_row($all_rows);
array_map('mysql_real_escape_string', $db_row);
$move[] = "'', "."'".implode("', '", $db_row)."'";
$f_move[] = "(".implode(', ', $move). ")";
$moved = implode(", ", $f_move);
print $moved;
$archive = 'INSERT INTO archive_rateplan VALUES '.$moved.'';
mysql_query($archive) or die(mysql_error());
//mysql_query($delete) or die(mysql_error());
}
and output still didn't do it
('', '192', 'America's Choice 450', '450', '39.9900.....
wow this is proving difficult!!!
vincenzobar
Forum Commoner
Posts: 95 Joined: Wed Nov 02, 2005 9:57 am
Post
by vincenzobar » Wed Nov 09, 2005 4:35 pm
LOL I feel like a retard... My brain is fried!!
I read over array_map and realized that about 2 seconds after i posted that!!!
code now looks like
Code: Select all
$move = array();
$f_move = array();
if(in_array($p_id, $DB_IDList)) {
$db_row = mysql_fetch_row($all_rows);
$dbf_row = array_map('mysql_real_escape_string', $db_row);
$move[] = "'', "."'".implode("', '", $dbf_row)."'";
$f_move[] = "(".implode(', ', $move). ")";
$moved = implode(", ", $f_move);
print $moved;
$archive = 'INSERT INTO archive_rateplan VALUES '.$moved.'';
mysql_query($archive) or die(mysql_error());
//mysql_query($delete) or die(mysql_error());
}
Thanks!