cs.punk Posted March 12, 2010 Share Posted March 12, 2010 Uhm Im kinda stuck... <?php if (isset($error)) {echo "<p class='error'>The following errors were found:</p> "; print_r ($error); // missing fields $error['empty'] = array(); foreach ($error['empty'] as $v) {echo "<p class='error'>$v</p>"; } // invalid size foreach ($error['size'] as $v) {echo "<p class='error'>$v</p>"; } // invalid format foreach ($error['format'] as $v) {echo "<p class='error'>$v</p>"; } } // Coming from the xhtml form if (!empty($_POST['title'])) {$rdata['title'] = mysqli_real_escape_string($con, $_POST['title']); } else {$error['empty'][] = "You have not entered a title."; } if (!empty($_POST['desc'])) {$rdata[''] = mysqli_real_escape_string($con, $_POST['desc']); } else {$error['empty'][] = "You have not entered a descreption."; } ?> But every time no error from one array is found but an error is found form another is still uses foreach on it.. and since its not set as an array it gives an error. I cant use $error['empty'] = array(); because it would blank it when there is an error... Warning: Invalid argument supplied for foreach() in D:\Chris\reco\xampplite\htdocs\admin\admin.php on line 164 A isset for each array? Is there an easier way? Link to comment https://forums.phpfreaks.com/topic/194987-using-foreach-to-echo-error-but-error-is-given-when-not-set/ Share on other sites More sharing options...
trq Posted March 12, 2010 Share Posted March 12, 2010 Try checking your variables against is_array before entering any foreach. Link to comment https://forums.phpfreaks.com/topic/194987-using-foreach-to-echo-error-but-error-is-given-when-not-set/#findComment-1025150 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.