안녕하세요 여러분, 일부 콘텐츠를 스크랩하기 위해 코드를 사용하고 있습니다. 이것을 mysql에 삽입해야한다. 또한 제목이 동일하고 게시물을 삽입하지 않는 경우 제목을 확인해야합니다.간단한 html dom과 mysql insert
내 코드 벨로우즈가 존재해도 첫 번째 레코드를 삽입합니다. 이 경우 > 0
에 == 1
을 변경하는
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 주입을 볼 ... 잘되지 –
은 귀하의 질문에 정확히 무엇이며? – derdida
당신의 의견에 대한 확인은 추한 것입니다. 왜 그것이 추한 이유를 설명하고 어떻게하면 더 안전하게 만들 수 있습니까? 나는 프로가 아니야, 노력하고있어! –