我一直在努力让我的数据插入到我的表中。数据从xml文件中拉入数组中,并且echo'ing结果正常,但插入失败。INSERT在服务器上失败,在
$dbhost = 'XXXX';
$dbuser = 'XXXX';
$dbpass = 'XXXX';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
if($conn)
{
echo "Database Connection Successfull...<br /><br />";
}
$dbname = 'a4027212_footy';
mysql_select_db($dbname) or die('Couldnt connect to database table');
if($dbname)
{
echo "Database ".$dbname." Selected..<br /><br />";
}
$tweetmeme = "http://api.tweetmeme.com/stories/popular.xml?category=sports-soccer&count=30" ;
$xml = @simplexml_load_file($tweetmeme) or die ("no file loaded") ;
if($xml)
{
echo "Tweetmeme XML loaded with ".count($xml->stories->story)." stories in the file..<br /><br />";
}
if(get_magic_quotes_gpc())
{
echo "Magic Quotes is ON<br /><br />";
}
foreach($xml->stories->story as $story)
{
$title=$story->title;
$title=mysql_real_escape_string($title);
$url=$story->url;
$url=mysql_real_escape_string($url);
$media_type=$story->media_type;
$media_type=mysql_real_escape_string($media_type);
$created=$story->created_at;
$created=mysql_real_escape_string($created);
$url_count=$story->url_count;
$url_count=mysql_real_escape_string($url_count);
$comment_count=$story->comment_count;
$comment_count=mysql_real_escape_string($comment_count);
$excerpt=$story->excerpt;
$excerpt=mysql_real_escape_string($excerpt);
$sql = "INSERT INTO ft_tweets (title,url,media_type,created_at,mention_count,comment_count,excerpt) VALUES ($title,$url,$media_type,$created,$url_count,$comment_count,$excerpt)";
$result = mysql_query($sql) or die(mysql_error());
if($result)
{
echo "added to database<br />";
}
}
echo "<br /><br />";
香港专业教育学院被告知,插入会如果有字符串和mysql_real_escape_string(在特殊字符)失败会帮助,但处理不当。我曾尝试过,但没有逃脱无济于事。
返回的错误消息是:您的SQL语法中有错误;检查与您的MySQL服务器版本相对应的手册,以获取在off附近使用的正确语法。脚踝在这里看起来很糟糕。 ?在Twitpic),mysql_real_escape_string(http://twitpic.c'在行1
和失败的SQL插入
该代码是一个烂摊子。我重新格式化了所有无关的换行符,但请在下次查看预览时确保它看起来可读。 – EboMike 2010-09-08 01:19:24
注意到,我只是复制粘贴,我会预览下一次:) – 2010-09-08 01:35:21