Ciao a tutti,
sto lavorando su un pasticcio pperato sul mio sito in Joomla dal plugin Joomla SEF Patch.
Tutti i 'metakey' e 'metadesc' sono stati inseriti nel campo 'metadesc' del database...attraverso preg_match_all sono riuscito ad isolare 'metakey' e 'metadesc'...
ora devo inserirli negli appositi campi, faccio partire lo script e ricevo questo avviso:
Match #1:
Field 'introtext' doesn't have a default value
quindi evinco che il problema sia proprio nell'inserimento dei nuovi metakey e metadesc estratti
Il codice in questione è questo:
Codice PHP:
<?php
$con = mysql_connect("localhost","joomla","joomla");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("old", $con);
$result = mysql_query("SELECT * FROM jos_content");
$cont = 0;
while($row = mysql_fetch_array($result))
{
$cont++;
$metakey = $row['metakey'];
$metadesc = $row['metadesc'];
$metadata = $row['metadata'];
// extraction of metadesc and metakey from metadata field
$pattern_desc = '{tion=(.*?)meta_k}si';
$pattern_key = '{words=(.*?)robots=}si';
//$matchcount = preg_match_all($pattern_long, $data, $matches);
$matchcount_desc = preg_match_all($pattern_desc, $metadata, $matches_desc);
$matchcount_key = preg_match_all($pattern_key, $metadata, $matches_key);
echo("<pre>\n");
if ($matchcount_desc > 0 || $matchcount_key > 0) {
// print_r($matches);
for($i = 0; $i < $matchcount_desc || $i < $matchcount_key; $i++) {
echo("\nMatch #" . ($cont) . ":\n");
$metadesc_new = ($matches_desc[1][$i]); // print 1st capture group for match number i
$metakey_new = ($matches_key[1][$i]); // print 1st capture group for match number i
if($metadesc == '' || !$metadesc){
mysql_query ("INSERT INTO `jos_content` (`metadesc`) VALUES ('".$metadesc_new."');") or die(mysql_error());
}
if($metakey == '' || !$metakey){
mysql_query ("INSERT INTO `jos_content` (`metakey`) VALUES ('".$metakey_new."');") or die(mysql_error());
}
}
} else {
echo('No matches');
}
echo 'Fine';
echo("\n</pre>");
}
mysql_close($con);
?>
Potreste aiutarmi per favore?