html - Error Passing Variable to Include in PHP 5.3 -


index.php

if (!$result)   {       $error = 'no value found.';     include 'error.html';       exit();   }   while ($row = mysqli_fetch_array($result))   {       $myvalues[] = $row['valueid'];    }   include 'output.html'; exit(); 

output.php

<?php foreach ($myvalues $allmyvalues): ?>       <?php echo $allmyvalues; ?>   <?php endforeach; ?>  

error "undefined variable: myvalues in ...output.php" rest of page displays properly.

using apache 2.2.15/php 5.3

any idea wrong? seems functioning, $myvalues not getting passed. running on windows 2k box, don't think upgrading apache/php option.

thanks in advance.

the problem you're assuming there no results found if $result false; however, return value returned if there query error. empty result set still considered successful query result. recommend moving logic around bit:

$myvalues = array(); if ($result) {     while (($row = mysqli_fetch_array($result)) !== false) {         $myvalues[] = $row['valueid'];     } } if (empty($myvalues)) {     $error = 'no value found.';     include 'error.html';       exit();   }   include 'output.php'; 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -