trenttdogg Posted March 1, 2017 Share Posted March 1, 2017 Hello, My issue is my php code working differently in different browsers. Here is the scenario: When a user fills in a field on the form, it searches my db and it there is an EXACT match, it sends them to "page2.php", if not it should send them to a page called "tryagain.php". This works perfectly in Firefox, but in IE and Chrome it sends them to "page2.php" but the page is blank. I believe the issue is in the 'or die' piece of code below. Any help would be greatly appreciated. $data = 'SELECT * FROM `users` WHERE `username` = "'.$search.'"'; $query = mysql_query($data) or die("Couldn't execute query. ". mysql_error()); $data2 = mysql_fetch_array($query)or die ('<META HTTP-EQUIV="Refresh" CONTENT="User Not Found;URL=tryagain.php">'); Quote Link to comment https://forums.phpfreaks.com/topic/303323-php-working-differently-in-different-browsers/ Share on other sites More sharing options...
benanamen Posted March 1, 2017 Share Posted March 1, 2017 (edited) So much wrong here. The entire code is junk. Toss it and learn PDO. https://phpdelusions.net/pdo Edited March 1, 2017 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/303323-php-working-differently-in-different-browsers/#findComment-1543570 Share on other sites More sharing options...
trenttdogg Posted March 1, 2017 Author Share Posted March 1, 2017 So much wrong here. The entire code is junk. Toss it and learn PDO. https://phpdelusions.net/pdo If I wanted an answer from a smart A$$, I could have asked my 13 year old son. Also, if I had the time/desire to learn a all the programming languages, I'd probably be a developer already and not be in a forum asking "dumb" questions. Right? So thanks anyway. Quote Link to comment https://forums.phpfreaks.com/topic/303323-php-working-differently-in-different-browsers/#findComment-1543571 Share on other sites More sharing options...
Solution cyberRobot Posted March 1, 2017 Solution Share Posted March 1, 2017 Are you trying to get the page to display "User Not Found" before the redirect happens? If so, you can see the example at the bottom of the following page: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta I think the issue is with the "User Not Found" text in the content attribute. Unless I missed something in the documentation, linked above, the value before the semi-colon needs to be a number. Side note: PHP has a function for redirecting the page. More information can be found here: http://php.net/manual/en/function.header.php Quote Link to comment https://forums.phpfreaks.com/topic/303323-php-working-differently-in-different-browsers/#findComment-1543572 Share on other sites More sharing options...
requinix Posted March 1, 2017 Share Posted March 1, 2017 1. The mysql extension and its mysql_* functions are old and unsupported. You need to start moving to either PDO (recommended) or mysqli. 2. I sure hope $search was escaped before you put it into that query. 3. die()ing with the MySQL error message is dangerous, not to mention a bad user experience. A Refresh value needs to be structured as "seconds;url=path", with the first part being a number of seconds to wait to redirect. 4. A meta refresh (as it's called) is a poor way to move users between pages. Use a header() redirect if you haven't created any output or display a message with a link on the page if you have. Quote Link to comment https://forums.phpfreaks.com/topic/303323-php-working-differently-in-different-browsers/#findComment-1543573 Share on other sites More sharing options...
benanamen Posted March 1, 2017 Share Posted March 1, 2017 You should have asked your 13 year old. He would have told you that your code is obsolete and has been completely removed from PHP and that your "code" is full of security vulnerabilities. PDO is not a new language. If you took a second to click on the link I provided you would have seen that. You are never going to be a programmer if you get butt hurt when someone tells you the truth. Quote Link to comment https://forums.phpfreaks.com/topic/303323-php-working-differently-in-different-browsers/#findComment-1543574 Share on other sites More sharing options...
trenttdogg Posted March 1, 2017 Author Share Posted March 1, 2017 Are you trying to get the page to display "User Not Found" before the redirect happens? If so, you can see the example at the bottom of the following page: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta I think the issue is with the "User Not Found" text in the content attribute. Unless I missed something in the documentation, linked above, the value before the semi-colon needs to be a number. Side note: PHP has a function for redirecting the page. More information can be found here: http://php.net/manual/en/function.header.php Yes. It was the "user not found" text in the content field that was creating the problem. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/303323-php-working-differently-in-different-browsers/#findComment-1543577 Share on other sites More sharing options...
trenttdogg Posted March 1, 2017 Author Share Posted March 1, 2017 You should have asked your 13 year old. He would have told you that your code is obsolete and has been completely removed from PHP and that your "code" is full of security vulnerabilities. PDO is not a new language. If you took a second to click on the link I provided you would have seen that. You are never going to be a programmer if you get butt hurt when someone tells you the truth. I agree. I know my code sucks and is outdated and am a complete hack. But I am not trying to become a programmer or developer. Just wanted to know why it worked differntly in different browsers, which was because I had text where it should have be a numeral. PDO is obviously the better option, just dont know it. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/303323-php-working-differently-in-different-browsers/#findComment-1543578 Share on other sites More sharing options...
benanamen Posted March 1, 2017 Share Posted March 1, 2017 I wasn't trying to be an ***. Programmer's (me included) can be terse in answering. The PDO tutorial link I gave you is very good. You should be able to grasp it fairly easy. We all had to start somewhere. I was basically trying to keep you from wasting your time and provide you the correct direction. Quote Link to comment https://forums.phpfreaks.com/topic/303323-php-working-differently-in-different-browsers/#findComment-1543579 Share on other sites More sharing options...
Jacques1 Posted March 2, 2017 Share Posted March 2, 2017 What you'll (hopefully) realize soon is that a lot of the “smartass answers” are far more valuable than the literal answers. When somebody asks you about the best way to drive a nail into the wall with an old shoe, you can tell them to use the sole. Or you can give them a hammer. Do you think the second option would make you an asshole who doesn't answer questions and wants everybody to become a professional craftsman? Or isn't it simply the right kind of help? The proposed alternative to your code is this: $userStmt = $databaseConnection->prepare('SELECT * FROM users WHERE username = :username'); $userStmt->execute(['username' => $search]); $user = $userStmt->fetch(); if (!$user) { echo 'User not found.<br><a href="tryagain.php">Go back</a>'; // not perfect, but definitely better than a page refresh exit; } This simultaneously solves your problem prevents your server from being compromised makes your application survive the next PHP update replaces the hacks with decent code And it's not exactly rocket science either. Sure, you're new to PHP, but you don't seem to be stupid. So why not spend a few minutes on learning something new instead of wasting days on ancient stuff that you'll sooner or later have to rewrite anyway? Quote Link to comment https://forums.phpfreaks.com/topic/303323-php-working-differently-in-different-browsers/#findComment-1543599 Share on other sites More sharing options...
cyberRobot Posted March 2, 2017 Share Posted March 2, 2017 echo 'User not found.<br><a href="tryagain.php">Go back</a>'; // not perfect, but definitely better than a page refresh You could also pass a flag to tryagain.php using a header() redirect. Then display the error message on the tryagain.php page. Quote Link to comment https://forums.phpfreaks.com/topic/303323-php-working-differently-in-different-browsers/#findComment-1543622 Share on other sites More sharing options...
Jacques1 Posted March 2, 2017 Share Posted March 2, 2017 Personally, I would put the form and the processing code into the same script. This is by far the easiest option and avoids “helper scripts” like this tryagain.php altogether. If that isn't an option, I'd store the message in the session or a cookie. When you use URL parameters, the message may appear unexpectedly (reloads, bookmarks, URL sharing, ...). Quote Link to comment https://forums.phpfreaks.com/topic/303323-php-working-differently-in-different-browsers/#findComment-1543626 Share on other sites More sharing options...
cyberRobot Posted March 2, 2017 Share Posted March 2, 2017 Personally, I would put the form and the processing code into the same script. This is by far the easiest option and avoids “helper scripts” like this tryagain.php altogether. Agreed If that isn't an option, I'd store the message in the session or a cookie. When you use URL parameters, the message may appear unexpectedly (reloads, bookmarks, URL sharing, ...). Hmm...I didn't think about that. Good point. Quote Link to comment https://forums.phpfreaks.com/topic/303323-php-working-differently-in-different-browsers/#findComment-1543627 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.