Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
| Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 5th, 2005, 01:02 PM
Registered User
 
Join Date: Oct 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default PHP code - works in Firefox, fails in IE

Hi,

I'm new to the whole web development idea; despite that, I've managed to learn PHP on the fly and write some code for a web application. The application, however, works in Firefox and not in IE.

I've traced the execution and found out that it breaks at the following section:

foreach( $postvars["ID_field"] as $key => $value )
{
    foreach( $_SESSION["RType_Name_Prefix"] as $name => $prefix )
    {
        if( strpos( strtoupper( $value ) , $prefix ) === 0 )
        {
            $rTypeID_tmp = $_SESSION["RType_Name_ID"][ $name ];
            $groupID_tmp = substr( $value, strlen( $prefix ), strlen( $value ));
            break;
        }
    }
}

Apparently, the code is not computing strpos correctly. For example, if prefix is 'V' and $value is 'V23', strpos returns 1. Then, of course, the if statemnt also fails and produces incorrect result.

This happens only in IE. Firefox works fine.

Any help (preferably at the earliest) is much appreciated.
 
Old October 5th, 2005, 01:09 PM
Friend of Wrox
Points: 1,315, Level: 14
Points: 1,315, Level: 14 Points: 1,315, Level: 14 Points: 1,315, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , .
Posts: 425
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hi there. :)

What's the output of the script and the context? Browsers know nothing about PHP. They only see the markup it may produce.

--
http://yupapa.com
 
Old October 5th, 2005, 01:50 PM
Registered User
 
Join Date: Oct 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, "meow" :)

Ok, here goes:

This script is executed on the server after the submission of the following form:

<form method=post action="<?php echo $_SERVER["PHP_SELF"] . "?View=7&Mod=" . $contID . ""; ?>
    <table>
        <tr>
            <td>ID</td>
        </tr>
        <tr>
            <td><input type="text" name="ID_field[]" value="&nbsp;"></td>
        </tr>
        <tr>
            <td><input type="submit" name="id_submit_btn" value="Submit"></td>
        </tr>
    </table>
</form>

The user enters an ID in the form e.g. V23. The script is then called, comparing the input value against $_SESSION["RType_Name_ID"], which is an associative array of the form:

Array(Vector=>V, Insert=>I, Oligo=>O, etc)

The script is supposed to extract the letter prefix from the input value and match it against the values of the array.

For some reason, when I enter "v23" into the form and hit submit, strpos("V23", "V") returns 1 and not 0, making my entire program fail.

This happens only when the application is viewed in Internet Explorer on Windows XP.

Thanks! :)
 
Old October 5th, 2005, 02:12 PM
Friend of Wrox
Points: 1,315, Level: 14
Points: 1,315, Level: 14 Points: 1,315, Level: 14 Points: 1,315, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , .
Posts: 425
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Sadly enough I don't know PHP (yet;)). But neither does IE so lets concentrate on the HTML.

Both your input tags lack the closing ">". But maybe you have it in the real page? "ID_field[]" isn't a kosher value for name. The spec says it should be CDATA but there are limitations.
http://www.w3.org/TR/html401/types.html#type-id

If the error is in the script someone else has to jump in. But the fact it only happens when you use IE points to that something's askew HTML wise.

--
http://yupapa.com
 
Old October 5th, 2005, 02:28 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

ID_field[] works fine for the name attribute. This is array syntax, in PHP this will become a variable like $_POST['ID_field'][$i], where $i is offset by the number of ID_fields that occur.

Check the value of the POST array, you might be getting different values from Explorer. Do this by dumping the contents of $_POST like so:

echo "<pre>";
var_dump($_POST);
echo "</pre>";

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old October 5th, 2005, 02:40 PM
Registered User
 
Join Date: Oct 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the dump result, Richard:

array(7) {
["ID_field"]=>
array(1) {
    [0]=>
    string(4) " v23"
}
... /other input values/ ...
["id_submit_button"]=>
string(6) "SUBMIT"
}

It's the same in both browsers... why would "v23" have length 4??
 
Old October 5th, 2005, 02:44 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Do you see the same output when you click view source and look at the dump?

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old October 5th, 2005, 02:46 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

> why would "v23" have length 4?

It would if the browser evaluated "&nbsp;" to a single space, which is the default value of your input field. I'd get rid of that.

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
 
Old October 5th, 2005, 02:47 PM
Registered User
 
Join Date: Oct 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Got it! You're right. Thanks so much, Rich!

:):):)
 
Old October 5th, 2005, 02:52 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

BTW, eventhough the error ended up being the default value of "&nbsp;". You can (and should) account for erraneous input problems like this by cleaning up your input data. You are already setting the input string to uppercase, but you aren't trimming leading and trailing whitespace. That's done with the trim() function.

http://www.php.net/trim



Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design




Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Table works in IE but not Firefox bumpy Javascript How-To 1 June 24th, 2007 03:47 PM
Shopping Cart works on Local Sys, but fails on IIS IronSights ASP.NET 2.0 Basics 0 July 27th, 2006 09:52 AM
Javscript works well in aspx page but fails... vivek_inos ASP.NET 1.0 and 1.1 Professional 2 June 18th, 2006 11:26 PM
Writing works then reading fails childoftv XSLT 3 April 22nd, 2006 04:09 AM
.ASP login page fails offline, but works online ?? putte74 Classic ASP Basics 1 January 10th, 2006 07:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.