I have written a code to do curl from text area from multiple url to store response data from URL. The problem is the programming is only repeatedly storing the first data only again and again in database. Kindly help me resolve this issue.
This is the code that is having the problem:
<?php
$db = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
if(isset($_POST['submit']))
{
$count=0;
$url_text=$_POST['content'];
$urls=explode(",",$url_text);
if(count($urls)>20)
{
echo "Url Should not exceed 20";
}
else
{
for($j=0;$j<count($urls);$j++)
{
if($urls[$j]!='')
{
$url=$urls[$j];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, '180');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, "");
$cUrlResponse = curl_exec($ch);
$httpResponseArr = curl_getinfo($ch);
curl_close($ch);
$new=explode("<td>",$cUrlResponse);
for($i=1;$i<count($new);$i++)
{
$new_input=explode("</td>",$new[$i]);
$content_input=explode(":",$new_input[0]);
$content[]=trim($content_input[1]);
}
$stmt4 = $db->prepare("insert into example (data1,data2,data3) values ('$content[0]','$content[1]','$content[2]')");
$stmt4->execute();
$count++;
}
echo $count." Rows Inserted Successfully....";
}
}
}
?>
<form method="post" method="">
<textarea name="content"></textarea>
<br>
<input type="submit" name="submit" value="Submit" />
</form>