Page 1 of 1

PHP & MySQL: repeating queries

Posted: Fri Aug 09, 2002 3:30 pm
by aaronvegh
Hi there,
I'm a fairly experienced PHPer, so this seems really weird.

When I write a block of code to insert data into a table, it works fine, but then I notice that about 15 minutes later, it repeats the insert. Another 15 minutes later, same thing! I left it overnight and the next day I had over 300 rows from what was originally a four-row insert!

I noticed the same problem when I wrote a block of code to pull email addresses from a table and send an email to those addresses. Every 15 minutes or so, the email would go out again. Erasing the table solved the problem.

Any suggestions? This is really mysterious! 8O
Thanks,
Aaron.

Can I see the code?

Posted: Fri Aug 09, 2002 3:36 pm
by Takuma
Can I see the PHP code and MySQL query?

Posted: Fri Aug 09, 2002 3:51 pm
by aaronvegh
No problem-o. This function takes the contents of a web page and inserts nito a database.

Code: Select all

function get_content($heading, $url, $unique_start, $unique_end, $isbn)
{

ini_set('max_execution_time', '0');

flush ();

$fd= fread(fopen("$url", "r"), 100000);
if ($fd)
{
	$start= strpos($fd, "$unique_start");

	$finish= strpos($fd, "$unique_end");

	$length= $finish-$start;

	$code=Substr($fd, $start, $length);
}
if($heading=="cover") {
	$code2 = eregi_replace("<a&#1111;^>.]*>","", $code);
	$code2 = eregi_replace("</a>", "", $code2);
	$code2 = str_replace("</font>
<span class=small>
<br>
<table border=0 align=left><tr><td valign=top align=center>", "", $code2);
&#125;
else &#123;
	$code2=strip_tags($code, '<ul><li>');
&#125;

if($heading=="title") &#123;
	$result=mysql_query("insert into books(title, isbn) values('$code2', '$isbn')");
	if(!$result) &#123;
		echo "Database insert failed on title!";
	&#125;
	else &#123;
		echo $heading . " inserted into database!<br>";
	&#125;
&#125;
else &#123;
	$result=mysql_query("update books set $heading='$code2' where isbn='$isbn'");
	if(!$result) &#123;
		echo "Database insert failed on $heading!";
	&#125;
	else &#123;
		echo $heading . " inserted into database!<br>";
	&#125;
&#125;



flush ();



&#125;
Thanks for your interest!
Aaron.