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
Post a Comment