Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/167144-solved-exploding-array-in-error-message/
Share on other sites

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
   } ?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.