Jump to content


Query works in FireFox but not in IE.. Why?!


5 replies to this topic

#1 Jshepp

    Young Padawan

  • Members
  • Pip
  • 11 posts
  • Gender:Male
  • Location:Canada
  • Interests:Creating websites, paintball, movies, hanging out.. you know, usual crap.

Posted 03 April 2008 - 05:15 PM

Hey, I have a search form that queries my database for what was searched. It works 100% perfect in Firefox, but doesn't return a thing in IE. Here's the script:
 <h2>Search the Database</h2>
 <p>Looking for a particular person? Search for them here!</p>
 
 
 
 <form id="search" action="database" method="POST"/>
 <p>What would you like to search?</p>
 <label for="search">Query: </label>
 <input type="text" name="query" id="query" maxlength="50" />
 <input type="submit" name="submit" class="button" value="Search" />
 
 
 
 </form>
 
 
 
 <?php
 
 if (isset($_POST["submit"])) {
	 //MySQL Connect
	 mysql_connect('xxx','xxx','xxx') OR die(mysql_error());
	 mysql_select_db('skills') OR die(mysql_error());
	 
	 $query = $_POST["query"];
	 if ($query == "") {
	 echo ("Please enter something in the search field.");
	 }else{
		 echo "Your search for <strong>$query</strong> came back with these results:\n
 
 \n";
	 $select = "SELECT * FROM users WHERE first LIKE '%$query%'" OR die(mysql_error());
	 $result = mysql_query($select) OR die(mysql_error());
	 $num = mysql_num_rows($result);
		 if ($num > 0 ) {
		 echo '<table class="users">'."\n".'<tr class="table_head"><th>First</th><th>Last</th><th>Username</th><th>E-Mail</th></tr>'."\n";
		 
			 while ($row = mysql_fetch_array($result)) {
				 
				 $fn = $row[first];
				 $ln = $row[last];
				 $user = $row[user];
				 $email = $row[email];
				 
				 echo "<tr><td>$fn</td><td>$ln</td><td>$user</td><td>$email</td></tr>\n";
			 }
		 echo "</table>\n";
		 }else{ echo "No results were found"; }
	 }
 }
 
 ?>
Now if i comment-out all the code inside that IF statement other than $query = $_POST["query"]; and then stick "echo $query;" after it, it'll echo what was searched just fine. Also, if I leave the field blank, it should return with "Please enter something in the search field"; but it doesn't in IE, yet works perfect in Firefox. Any help / suggestions?

#2 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 03 April 2008 - 05:47 PM

might have something to do with:
<form id="search" action="database" method="POST"/>

is your file called 'database' or 'database.php'... Your action may be wrong

#3 Jshepp

    Young Padawan

  • Members
  • Pip
  • 11 posts
  • Gender:Male
  • Location:Canada
  • Interests:Creating websites, paintball, movies, hanging out.. you know, usual crap.

Posted 03 April 2008 - 06:03 PM

Nah I have a .htaccess redirect set up so "database" works fine. Remember, the exact script works perfect in Firefox. =/

#4 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 03 April 2008 - 06:55 PM

Yeh I would've guessed you had something like that. But the PHP code is browser independent (PHP = server side ..) So there must be something wrong with sending the variables to the server. So your HTML code.
Either that or it's something with isset. Try replacing this:
if (isset($_POST["submit"])) {
by this:
if (isset($_POST["submit"]) || !empty($_POST["submit"])) {
Maybe IE puts an empty string in the variable before sending instead of assinging it with 'null' as value



B

#5 Jshepp

    Young Padawan

  • Members
  • Pip
  • 11 posts
  • Gender:Male
  • Location:Canada
  • Interests:Creating websites, paintball, movies, hanging out.. you know, usual crap.

Posted 03 April 2008 - 07:52 PM

Well that helps to solve the problem of it not detecting an empty string but a valid one still doesn't come back with anything. Grr...

Edit: Ok soo.. I switched isset to !empty, and now when I type something in and press enter, nothing comes up. But if I click the Search button, it works! So for whatever reason, it doesn't read the submit button unless it's clicked. Wtf? lol.

Edit 2: Ok so i fixed it with this:
<input type="hidden" name="formsent" value="1" />
....
if ($_POST["formsent"] == 1) {
...

Edited by Jshepp, 03 April 2008 - 08:09 PM.


#6 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 03 April 2008 - 08:09 PM

Edit: You edited your post!

die('<pre>'.htmlspecialchars(print_r($_POST,1)).'</pre>');
Put that in your code on the line after the opening php tag. Then copy/paste the results here (for IE only, both when submit is clicked and when enter is pressed).

Also, do you have any other javascript/htaccess codes that may affect things (i.e. is the code you posted EVERYTHING, or just a snippit)?

End edit;

View Postdotbart, on Apr 3 2008, 05:55 PM, said:

Either that or it's something with isset. Try replacing this:
if (isset($_POST["submit"])) {
by this:
if (isset($_POST["submit"]) || !empty($_POST["submit"])) {
Maybe IE puts an empty string in the variable before sending instead of assinging it with 'null' as value

B
Good guess, but you missed one detail:

Quote

Now if i comment-out all the code inside that IF statement other than $query = $_POST["query"]; and then stick "echo $query;" after it, it'll echo what was searched just fine.
The way he worded that, it has no problem getting inside of the if AND passing $_POST['query'], but breaks somewhere else...

Since absolutely nothing is displayed, that makes me think it is a html problem, not a php problem. Could you run a quick search and post the resulting HTML source code (for both IE and FF)?

Edited by rc69, 03 April 2008 - 08:11 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users