你好,我正在使用下面的代码来取消一些内容。 我需要插入到MySQL。此外,我必须检查标题,如果是相同的,如果它不插入帖子。简单的html dom和mysql插入
我的代码在下面插入第一条记录,即使它存在。
foreach($html->find('div.article_item') as $div) {
$title = $div->find('h2.title a ', 0)->innertext;
$thumb = $div->find('p.image_left img ', 0)->src;
$details = $div->children(3)->plaintext;
$url = $div->find('p.more a', 0)->href;
//I need only 3 posts to grab
for($i= 0 ; $i <= 3 ; $i++)
{
$qry="SELECT * FROM posts WHERE posttitle ='$title'";
$result=mysqli_query($connectiondb, $qry);
//Check whether the query was successful or not
if($result) {
if(mysqli_num_rows($result) == 1) {
//Post Exists
}else {
$posttitle = $title;
$postthumb = $thumb;
$postdetails = $details;
$posturl = $url;
mysqli_query ($connectiondb, "INSERT INTO posts (posttitle, postthumb, postdetails, posturl) VALUES ('$posttitle', '$postthumb','$postdetails','$posturl')");
}
}else {
(mysqli_error());
}
mysqli_close($connectiondb);
}
// Clear dom object
$html->clear();
unset($html);
}
那么难看缩进和这么多的SQL注入......不好 – 2014-09-27 00:11:10
而究竟是什么你的问题? – derdida 2014-09-27 00:12:02
好的在你的oppinion是丑陋的..请至少解释为什么它很丑,我怎样才能让它更安全?我不是职业球员,我正在努力! – 2014-09-27 00:24:14