Jump to content

[SOLVED] Mysql query gets executed several times for wrong html in php function


kellerkind

Recommended Posts

Hi,

this problem drove me nuts for a couple of hours. A mysql query got executed several times even though it was in no loop or anything else that could have caused it.

I pinned it down to one external php function and actually solved the problem while I made a function to show here. I just want to share this because it seems quiet uncommon. Would be nice to get some comments on it.

 

Ok first i connect to mysql nothing special here

mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("the_db") or die(mysql_error());

 

 

This here is the query that gets added three times to the table in my db. Nothing special as well.

$addsize = "INSERT INTO `temp_cart` (`id` ,`sess_id` ,`item_name` ,`item_id` ,`item_info` ,`item_use`,`item_code`,`item_price`) VALUES (NULL, '2', '2', '2', '2', '2', '2', '2')";

$result = mysql_query($addsize)
or die(mysql_error());  

 

Here comes the evil php function that caused the problem and was the reason that all queries on this site got exectued twice. (I made it shorter that its easy to read)

 

function stepimg($image, $title, $subheader, $extended = 0, $extra = 0) {

echo '<table cellpadding="0" cellspacing="0" border="0" background="#222222" width="580">
<tr>
    	<td width="125">
        </td>
        <td width="455">
        	'.$title;
        echo '</td>
   	</tr>
</table>';

}

stepimg("img/checkout.gif" ,"Checkout" , "Please enter your details", "Checkout");		

 

This looked pretty good to me but the problem was:

 

background="#222222" 

 

I never ever thought that this could cause a mysql query to execute several times. It's kinda funny as more often you add a table with background="#222222" as more often the query gets executed. I had it two times in this function so the mysql query got executed three times.

 

Can anyone tell me why this happened? Does the page load more often or what?

 

 

 

 

 

Link to comment
Share on other sites

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.