|
Posted by Wolf on 02/05/06 17:47
Dear all!
I have a big problem in the backup of mysql database: I want to move
fields from table 1 to table 2, using a script. But there are troubles
with special chars like ' and ". I tried to make a function to protect
fields, but it does not work! :( Anyone can help me please?
Thank to all for any suggestions! :)
This is the script (gb_timestamp is in datetime format):
# for connection
include ("conn_m_inc.php");
# special chars function
function strip_it($str) {
$str=urldecode($str);
$str=stripslashes($str);
$str=htmlspecialchars($str);
return($str);
}
# select from table 1
$sql = mysql_query("SELECT gb_id, gb_name, gb_cosa, gb_message,
UNIX_TIMESTAMP(gb_timestamp) as time, gb_user5 FROM envo_envoGB_GB ORDER
BY gb_id");
# insert in the 2nd table
while ($riga = mysql_fetch_array($sql))
{
$gb_id=strip_it($gb_id);
$time=strip_it($time);
$gb_user5=strip_it($gb_user5);
$gb_name=strip_it($gb_name);
$gb_cosa=strip_it($gb_cosa);
$gb_message=strip_it($gb_message);
$gb_id=$riga["gb_id"];
$time=$riga["time"];
$gb_user5=$riga["$gb_user5"];
$gb_name=$riga["gb_name"];
$gb_cosa=$riga["gb_cosa"];
$gb_message=$riga["gb_message"];
$res=mysql_query("INSERT INTO envo_textnews VALUES ('$gb_id', '$time',
'$gb_user5', '$gb_cosa', '$gb_message', '$gb_name')");
# it works?
if(!$res)
{
echo " $gb_id - Error in transfer!<BR>\n";
} else {echo "Variables Transfered!<br>\n";}
}
[Back to original message]
|