ktroztafy Posted December 26, 2011 Share Posted December 26, 2011 Hello everyone, I'm new here first post, but there's a weirdness in code that i need to share, First of all, I know everyone who knows PHP/MYSQL will say the same thing... Server side code cannot be broken by a browser, especially by client side coding. I agree!!! That may be the case here too, but I have encountered one of the weirdest code ever and the client side code is causing an unexpected result in PHP/MYSQL, and only in Internet Explorer. Unexplainable, and I am seeking for an answer. After hours of trouble shooting I finally targeted the the trouble code... and it's CSS, and it's affecting a MYSQL line of code in PHP... #somediv { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=''); } ... anyways let me explain how the code should run and the problem... in one page a variable passed in the URL is being captured by PHP using the $_GET method, if that variable is empty PHP runs a code which updates a MYSQL database. That works fine, and as expected, except in INTERNET EXPLORER. On that same page, a css file which is to be included with the output html to the browser contains the above line of css too. Now in every other browser that code works as expected, if the variable is NOT empty, update the database and then output the html code. In IE the database gets updated no matter what, whether the variable is empty of not. Now the its only the mysql code inside the IF statement that get affected, because for troubleshooting purposes I have put echo statements inside the code, to catch the problem, and the echo statements work as should, just not the mysql update statement. Someone care to shed some light into this mystery? Quote Link to comment https://forums.phpfreaks.com/topic/253833-phpmysql-broken-by-the-evil-browser-internet-explorer/ Share on other sites More sharing options...
KevinM1 Posted December 26, 2011 Share Posted December 26, 2011 Can you show us the relevant code? Quote Link to comment https://forums.phpfreaks.com/topic/253833-phpmysql-broken-by-the-evil-browser-internet-explorer/#findComment-1301334 Share on other sites More sharing options...
ktroztafy Posted December 26, 2011 Author Share Posted December 26, 2011 Just to make things clear.. here's an example of the code... if (empty($_GET["variable"])){ $update = mysql_query("UPDATE database set field='variable is empty' where id='1' "); } // then all the html header stuff gets outputed by PHP including a linked rel CSS file wich contains the next line #somediv {filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=''); } // then the BODY and HTML stuff is included... which should have no effect on the PHP, but also including a div with the id=somediv ... and thats pretty much it in every browser, if the $_GET variable is empty the database is updated, in IE, no matter what the database gets updated.... when i remove the line of code from the CSS, that php code works as expected... how that CSS line of code affects my MYSQL database code is beyond me... but it's happening Quote Link to comment https://forums.phpfreaks.com/topic/253833-phpmysql-broken-by-the-evil-browser-internet-explorer/#findComment-1301335 Share on other sites More sharing options...
PFMaBiSmAd Posted December 26, 2011 Share Posted December 26, 2011 It's likely that statement is causing your page to be requested twice, once with an expected URL and once with an empty query string on the end of the URL. I would log (see the error_log statement) the date/time date('Y-m-d H:i:s') and $_SERVER['REQUEST_URI'] right before your if(empty()){} logic so that you can see exactly if, when, how many times, and what is being requested on the end of the URL. Quote Link to comment https://forums.phpfreaks.com/topic/253833-phpmysql-broken-by-the-evil-browser-internet-explorer/#findComment-1301341 Share on other sites More sharing options...
kicken Posted December 26, 2011 Share Posted December 26, 2011 It's likely that statement is causing your page to be requested twice, once with an expected URL and once with an empty query string on the end of the URL. I agree, that is almost surely the case. Similar to when you have an <img src=""> in your code, the browser will load the page again to try and use it for the image. The reason your only seeing the problem in IE in this case is because IE is the only browser that understands that CSS code. Every other browser will treat that line as an error and ignore it. Quote Link to comment https://forums.phpfreaks.com/topic/253833-phpmysql-broken-by-the-evil-browser-internet-explorer/#findComment-1301342 Share on other sites More sharing options...
ktroztafy Posted December 26, 2011 Author Share Posted December 26, 2011 That's what I thought, but lets say I add an echo statement, just to keep it simple like the following... if (empty($_GET["variable"])){ $update = mysql_query("UPDATE database set field='variable is empty' where id='1' "); echo "DATABASE WAS UPDATE"; } The echo statement works as expected in EVERY browser, including IE. But that MySQL line does not. The MYSQL still updates, even if the $_GET[] is empty or not. That's just weird to me. Quote Link to comment https://forums.phpfreaks.com/topic/253833-phpmysql-broken-by-the-evil-browser-internet-explorer/#findComment-1301345 Share on other sites More sharing options...
PFMaBiSmAd Posted December 26, 2011 Share Posted December 26, 2011 Echoing something on the page won't accurately show what is happening if the page is being requested twice (you will only see the output from the last time the page is being requested), because the echoed output or lack there of will be replaced by the complement (lack of echoed output or the expected echoed output) on the second page request, which is why someone recommend logging definitive information about the page requests to help troubleshoot the problem. Edit: Here's another possibility that could fit these symptoms. You have a header redirect somewhere that doesn't have an exit; statement after it and when the remainder of the code on your page runs while the browser is making the request for the new page, the remainder of the code on that page causes your update query to run/not-run. This offending IE statement being present in the css on the page could affect if/when/how long the redirect takes and affects if the problem shows itself. I would recommend posting enough of your code that reproduces the problem so that someone could pin down the actual cause. Quote Link to comment https://forums.phpfreaks.com/topic/253833-phpmysql-broken-by-the-evil-browser-internet-explorer/#findComment-1301346 Share on other sites More sharing options...
ktroztafy Posted December 26, 2011 Author Share Posted December 26, 2011 Ok here's is the EXACT code I am trouble shooting <? // Here we connect to the database $database = mysql_connect("****","*****","******"); if (!$database) die ("could not connect"); mysql_select_db("*******") or die ("MYSQL DID NOT FIND A CONNECTION:". mysql_error()); //here is the code which is not working as expected in IE if (empty($_GET["variable"])){ $update = mysql_query("UPDATE database set field='variable is empty' where id='1' "); echo "DATABASE WAS UPDATED"; } ?> <!DOCTYPE HTML><html lang="en" > <head><meta charset="utf-8"> <title>TEST</title> <style> #somediv {filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=''); } </style> </head> <body> <div id="somediv"> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/253833-phpmysql-broken-by-the-evil-browser-internet-explorer/#findComment-1301349 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.