graham23s Posted June 23, 2008 Share Posted June 23, 2008 Hi Guys, i can't figure out the best way to do this, this piece of code: } elseif ($_GET['action'] == 'add-url') { // Deal with post data if (isset($_POST['submit'])) { // post vars $var_url = $_POST['url']; $var_des = $_POST['desc']; // initialise array $errors = array(); // empty fields if (empty($var_url)) { $errors[] = "You never entered a URL."; } // empty fields if (empty($var_des)) { $errors[] = "You never entered a Brief description of your site."; } // show any errors found if (!isset($errors)) { // NO ERRORS print("THANK YOU!!!!!!!"); } else { print("<div id=\"bullet_box\">"); print("<ul class=\"bullets\">"); foreach($errors as $error) { print("<li>$error"); } print("</ul>"); print("</div>"); } } // end isset // print form add url print("<form action=\"\" method=\"POST\" name=\"submit_page\">\n"); print("<table width=\"500\" border=\"0\" cellpadding=\"5\" cellspacing=\"2\">\n"); print("<tr>\n"); print("<td align=\"left\" colspan=\"2\"><h2>Submit URL</h2></td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td align=\"left\">URL:</td><td align=\"left\"><input type=\"text\" name=\"url\" size=\"40\"></td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td align=\"left\">Brief Description:</td><td align=\"left\"><input type=\"text\" name=\"desc\" size=\"40\"></td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td align=\"left\"><input type=\"submit\" name=\"submit\" value=\"Add URL\"></td><td align=\"left\"><span class=\"star\">*</span> We will crawl your site in 2-3 days!</td>\n"); print("</tr>\n"); print("</table>\n"); print("</form>\n"); } else { include("results.php"); } ?> if there are errors, i print a bullet list of the errors with a css border round it, works great untill there are no errors, then it just prints the bullet list with nothing in it! it doesn't seem to execute the no errors part! its probably really simple to thanks guys Graham Quote Link to comment Share on other sites More sharing options...
DoddsAntS Posted June 23, 2008 Share Posted June 23, 2008 Hi, You're setting the variable $errors to be an array then checking to see if it is set. Leave the majority of the setup the way you have it just change the logic of the if statment to be if(count($errors) > 0) { //display error code } else { //display thanks no errors code } Quote Link to comment Share on other sites More sharing options...
graham23s Posted June 23, 2008 Author Share Posted June 23, 2008 Brill! thanks mate that done the trick Graham Quote Link to comment 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.