 |
| 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
|
|
|
|

October 5th, 2005, 01:02 PM
|
|
Registered User
|
|
Join Date: Oct 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

October 5th, 2005, 01:09 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 425
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

October 5th, 2005, 01:50 PM
|
|
Registered User
|
|
Join Date: Oct 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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=" "></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! :)
|
|

October 5th, 2005, 02:12 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 425
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

October 5th, 2005, 02:28 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
|
|
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
|
|

October 5th, 2005, 02:40 PM
|
|
Registered User
|
|
Join Date: Oct 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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??
|
|

October 5th, 2005, 02:44 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
|
|
|
|

October 5th, 2005, 02:47 PM
|
|
Registered User
|
|
Join Date: Oct 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Got it! You're right. Thanks so much, Rich!
:):):)
|
|
 |