你好,我正在使用下面的代碼來取消一些內容。 我需要插入到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