Welcome Guest, Not a member yet? Register   Sign In
Weird shiznit: while/each works local, but not on live server
#1

[eluser]codex[/eluser]
This loop has worked and still works on several servers, but stopped working on a new one. What may have something to do with it is that the other servers are PHP4, and this new one is PHP5. But that's still odd since locally I have Wamp running on PHP5 without problems. I'm stumped.

Code:
while (list (, $val) = each ($_POST['domain_category']))
        {
            $this->db->set('link_domain_id', $domain_id);
            $this->db->set('link_category_id', $val);
            $this->db->insert('domains_categories_link');
         }

This is one of the checkboxes:

Code:
<input type="checkbox" name="domain_category[]" value="104" />
#2

[eluser]gtech[/eluser]
Hi codex,

maybe you could drop this controller on your server, it worked for me on php 5.2.1. check the post data, then try comment out the first loop if that fails and try the second method of looping... only an idea as I havn't the foggest.
Code:
<?php
class Temp extends Controller {
    function Temp()
    {
        parent::Controller();    
    }
    function index()
    {
        echo '<form action="'.site_url().'/temp/postto" method="post">';
        echo '<input type="checkbox" name="d_c[]" value="104" />';
        echo '<input type="checkbox" name="d_c[]" value="105" />';
        echo '<input type="submit" /></form>';
    }
    function postto() {
      // check postdata
      print_r($_POST);
      echo "<br>";

      // 1st loop method comment out if fails.
      while (list (, $val) = each ($_POST['d_c']))
      {
        echo $val."<br>";
      }
      echo "<hr>";

      // 2nd loop method
      foreach ($_POST['d_c'] as $key => $val) {
          echo $val."<br>";
      }
    }
}
?&gt;
#3

[eluser]codex[/eluser]
[quote author="gtech" date="1211344292"]Hi codex,

maybe you could drop this controller on your server, it worked for me on php 5.2.1. check the post data, then try comment out the first loop if that fails and try the second method of looping... only an idea as I havn't the foggest.
[/quote]

Hey, I didn't think of trying

Code:
// 2nd loop method
      foreach ($_POST['d_c'] as $key => $val) {
          echo $val."<br>";
      }

but that actually does the trick. Thanks for pointing me in the right direction.

But does anyone know why? I mean, it's just a plain old while loop. What's different about PHP5 that may be causing this behaviour?




Theme © iAndrew 2016 - Forum software by © MyBB