kellerkind Posted October 24, 2007 Share Posted October 24, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/74617-solved-mysql-query-gets-executed-several-times-for-wrong-html-in-php-function/ Share on other sites More sharing options...
only one Posted October 24, 2007 Share Posted October 24, 2007 echo " <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" background=\"#222222\" width=\"580\"> <tr> <td width=\"125\"> </td> <td width=\"45\5"> $title </td> </tr> </table>"; Quote Link to comment https://forums.phpfreaks.com/topic/74617-solved-mysql-query-gets-executed-several-times-for-wrong-html-in-php-function/#findComment-377167 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.