conker87 Posted July 23, 2009 Share Posted July 23, 2009 I have a website where users can upload articles, reviews etc, etc. I have the basic upload script made (the site is quite old now) but I want to add some error catching in it. I have this so far: <?php if (empty($_POST['title'])) { $error[] = "title"; $errorb = true; } if (empty($_POST['platform'])) { $error[] = "platform"; $errorb = true; } if (empty($_POST['genre'])) { $error[] = "genre"; $errorb = true; } if (empty($_POST['content'])) { $error[] = "content"; $errorb = true; } if (empty($_POST['rate'])) { $error[] = "rate"; $errorb = true; } if (empty($_POST['copyright'])) { $error[] = "copyright"; $errorb = true; } if ($errorb == true) { $body .= "<h3 style='color: red;'>You must fill in the following fields: <fields>.</h3>"; } else { //etc } ?> Now I'm not too sure how to explode the $error array so it'll echo something like "title, content" etc if they are empty in the $body variable. Can anyone shed some light? Quote Link to comment https://forums.phpfreaks.com/topic/167144-solved-exploding-array-in-error-message/ Share on other sites More sharing options...
akitchin Posted July 23, 2009 Share Posted July 23, 2009 here you'll actually want implode(). i should also point out that you don't need to set the $errorb flag - simply checking if the $error array exists is sufficient, since it won't be defined unless one of the fields is missing: if (empty($_POST['copyright'])) { $error[] = "copyright"; } if (isset($error) && !empty($error)) { $body .= "<h3 style='color: red;'>You must fill in the following fields: ".implode(', ', $error).".</h3>"; } else { //etc } ?> Quote Link to comment https://forums.phpfreaks.com/topic/167144-solved-exploding-array-in-error-message/#findComment-881324 Share on other sites More sharing options...
conker87 Posted July 23, 2009 Author Share Posted July 23, 2009 Works great, cheers. i should also point out that you don't need to set the $errorb flag - simply checking if the $error array exists is sufficientWas totally in c# mode then XD Quote Link to comment https://forums.phpfreaks.com/topic/167144-solved-exploding-array-in-error-message/#findComment-881326 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.