Jump to content

Recommended Posts

Hey,

 

Im working on a script that uses cURL to login to a site and go to a page, and using limiters and delimiters i select what I want and then I tried to do if statements to make it not add items that were already added and it goes into an infinite loop for some reason, here is my code:

 


<?php
require("config.php");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://quiver.outwar.com/myaccount.php');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'login_username=xxxxx&login_password=xxxxx');
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
curl_setopt($ch, CURLOPT_URL, 'http://quiver.outwar.com/crew_actionlog.php?suid=55726&serverid=6');
$result1 = curl_exec($ch);

echo strip_tags($result1);

$query="select * from actionlog";
$result=mysql_query($query); 
echo mysql_num_rows($result);

curl_close ($ch);
$c=explode("\n",strip_tags($result1));
$s=false;
$i=$r=0;
$o=array();
foreach($c as $k=>$v){
$c[$k]=trim($c[$k]);
if($c[$k]=='Dehitlist'||$c[$k]=='Next >>'){
  $s=($c[$k]=='Dehitlist');
  unset($c[$k]);
  continue;
}
if(empty($c[$k])||$s===false){
  unset($c[$k]);
  continue;
}
if($i==3){
  $i=0;
  $r++;
}
$o[$r][$i]=$c[$k];
$i++;
}
foreach($o as $k=>$v){
$v[3]=(eregi('Awarded',$v[1]))? 'Awarded' : 'Deposited'; 
echo $v[1];
preg_match("~(?:Deposited|Awarded)\s([^\(]+)\s\(([^\)]+)\)(?:\sto\s([^\b]+))?~",$v[1],$match);
echo "<pre>"; print_r($match); echo "</pre>";
while($result = mysql_query($query)) {
  if($result['id'] == $match[2]) {
  } else {
if ($v[3] == 'Awarded')
{
mysql_query("INSERT INTO `actionlog` (`name`,`item`,`date`,`action`,`itemid`) VALUES ('{$match[3]}','{$match[1]}','{$v[2]}','{$v[3]}','{$match[2]}')")or die ("MySQL Error". mysql_error()); 
}
else if ($v[3] == 'Deposited')
{
mysql_query("INSERT INTO `actionlog` (`name`,`item`,`date`,`action`,`itemid`) VALUES ('{$v[0]}','{$match[1]}','{$v[2]}','{$v[3]}','{$match[2]}')")  or die ("MySQL Error". mysql_error()); 
}
else{}
}
}



}



?>

Link to comment
https://forums.phpfreaks.com/topic/140052-infinite-loop-problem/
Share on other sites

<?php
while($result = mysql_query($query)) {
?>

 

I believe that should be ==.

 

This always returns true.

 

Almost buddy, keep the single equals but change mysql_query to mysql_fetch_assoc...

 

$res = mysql_query($query);
while($result = mysql_fetch_assoc($res)) {

 

Should correct that issue.

 

EDIT:

Looking at your code, you define $result earlier on, so you probably do not need the extra mysql_query, but change that reference to be $res instead, so you do not have to change all instances of $result to be $row

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.