Jump to content

Recommended Posts

Hello,

I'm having a problem with Internet Explorer and a $_POST array. The code works fine through Firefox.

 

I display lines like so:

$result= mysql_query($query) or die ("query failed.");

 

while ( $row = mysql_fetch_array($result))

{

extract($row);

 

echo "<p><img src='$isbn.jpg' border='0' width='55' height='80'> $word : $isbn <form action= 'displaydata.php' method= 'post'><input type= 'hidden' name='isbn' value= '$isbn'><input type= 'submit' value= 'more'</form>\n";

}

 

In both browsers, all displays fine. Clicking the 'more' button sends the variable $isbn to 'displaydata.php'.

 

This from 'displaydata.php':

foreach ($_POST as $field => $value)

{

echo "$field -> $value<br>";

}

$query= "select * from title where isbn like '$value'";

 

If the first program returns a list of five items, and I click the more button on the second item, In Firefox, the $isbn that is assigned to $value is the one expected. However, in IE, the $value *always* is the last $isbn from the list of five the first program returns.

 

I have discovered that in IE, the array $_POST is all five $isbn from the first program, so what is being assigned to $value is the last one that appears. In Firefox, the array $_POST is only the one selected $isbn.

 

Help! What needs to be changed so that only the selected $isbn from the first program is passed to 'displaydata.php'?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/138751-problem-with-_post-array/
Share on other sites

Should not matter browser wise. Not sure why it is, but the PHP does not know or care about the browser.

 

As far as why your code does not work.

 

foreach ($_POST as $field => $value)
      {
      echo "$field -> $value<br>";
      }
$query= "select * from title where isbn like '$value'";

 

Should always display the last $value, since the $query is not in the loop. That just makes no sense. This would be better.

$isbn = isset($_POST['isbn'])?$_POST['isbn']:'';
$query= "select * from title where isbn like '$isbn'";

 

Should get correct results each time.

Thanks Premiso--

I made the change, but IE still returns incorrect results...Firefox is fine.

 

In the first program, if I change: name='$isbn' like so:

 

echo "<p><img src='$isbn.jpg' border='0' width='55' height='80'> $word : $isbn <form action= 'displaydata.php' method= 'post'><input type= 'hidden' name='$isbn' value= '$isbn'><input type= 'submit' value= 'more'</form>\n";

 

In 'displaydata.php' if I add the line: print_r($_POST);

 

When I submit, in Firefox, the one isbn selected is displayed. That is, only one is being passed in $_POST, so only one isbn is available to:

$query= "select * from title where isbn like '$isbn'";

 

Array ( [9780268011949] => 9780268011949 )

 

In IE, ALL the isbn's from the previous program are being passed in $_POST, and of all of them, the very last isbn is being used for:

$query= "select * from title where isbn like '$isbn'";

 

Array ( [9780060626457] => 9780060626457 [9780268011857] => 9780268011857 [9780268011949] => 9780268011949 [9780268022082] => 9780268022082 [9780268025939] => 9780268025939 [9780268032616] => 9780268032616 [9780268032623] => 9780268032623 [9780486425016] => 9780486425016 [9780548054673] => 9780548054673 [9780595094578] => 9780595094578 [9780761835134] => 9780761835134 [9780764808456] => 9780764808456 [9780764811074] => 9780764811074 [9780764812859] => 9780764812859 [9780766180932] => 9780766180932 [9780802087188] => 9780802087188 [9780809121229] => 9780809121229 [9780809137558] => 9780809137558 [9780809138234] => 9780809138234 [9780809140138] => 9780809140138 [9780809144556] => 9780809144556 [9780812974218] => 9780812974218 [9780813215228] => 9780813215228 [9780814660126] => 9780814660126 [9780815628767] => 9780815628767 [9780815628774] => 9780815628774 [9780818907449] => 9780818907449 [9780818908026] => 9780818908026 [9780818909498] => 9780818909498 [9780818909603] => 9780818909603 [9780819839800] => 9780819839800 [9780819909886] => 9780819909886 [9780824516284] => 9780824516284 [9780824517908] => 9780824517908 [9780824519964] => 9780824519964 [9780824521066] => 9780824521066 [9780824523435] => 9780824523435 [9780824523459] => 9780824523459 [9780824524906] => 9780824524906 [9780824525040] => 9780824525040 [9780824525118] => 9780824525118 [9780826481092] => 9780826481092 [9780829420418] => 9780829420418 [9780852445624] => 9780852445624 [9780867163711] => 9780867163711 [9780867164305] => 9780867164305 [9780867167467] => 9780867167467 [9780877939856] => 9780877939856 [9780879073169] => 9780879073169 [9780892837502] => 9780892837502 [9780895554369] => 9780895554369 [9780915138494] => 9780915138494 [9781405120838] => 9781405120838 [9781405120845] => 9781405120845 [9781417978847] => 9781417978847 [9781555409326] => 9781555409326 [9781556126598] => 9781556126598 [9781557255259] => 9781557255259 [9781564596086] => 9781564596086 [9781565482432] => 9781565482432 [9781565482487] => 9781565482487 [9781570751752] => 9781570751752 [9781570752063] => 9781570752063 [9781570753121] => 9781570753121 [9781570756757] => 9781570756757 [9781584591771] => 9781584591771 [9781584593515] => 9781584593515 [9781591790235] => 9781591790235 [9781596270893] => 9781596270893 [9781604592641] => 9781604592641 [9781843840077] => 9781843840077 )

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.