andre25 Posted March 25, 2012 Share Posted March 25, 2012 I had a problem with my code, the result shows 'Fatal error: Cannot redeclare create_form_input() (previously declared in ....\form_functions.inc.php:9) in ....\includes\form_functions.inc.php on line 32 I need to make registration forms and I already defined a function for creating this inputs.. here's the code <?php function create_form_input($name, $type, $errors) { $value = false; if (isset($_POST[$name])) $value = $_POST[$name]; if ($value && get_magic_quotes_gpc( )) $value = stripslashes($value); if ( ($type == 'text') || ($type == 'password') ) { echo '<input type="' . $type . '" name="' . $name . '" id="' . $name . '"'; if ($value) echo ' value="' . htmlspecialchars($value) . '"'; if (array_key_exists($name, $errors)) { echo 'class="error" /> <span class="error">' . $errors[$name] .'</span>'; } else { echo ' />'; } } elseif ($type == 'textarea') { if (array_key_exists($name, $errors)) echo ' <span class="error">' .$errors[$name] . '</span>'; echo '<textarea name="' . $name . '" id="' . $name . '" rows="5" cols="75"'; if (array_key_exists($name, $errors)) { echo ' class="error">'; } else { echo '>'; } if ($value) echo $value; echo '</textarea>'; } // End of primary IF-ELSE. } // End of function And here is the form registration. <?php require ('./includes/form_functions.inc.php'); ?> <form action="register.php" method="post" accept-charset="utf-8" style="padding-left:100px"> <p><label for="first_name"><strong>First Name</strong></label> <br /><?php create_form_input('first_name', 'text', $reg_errors); ?></p> <p><label for="last_name"><strong>Last Name</strong></label><br /><?php create_form_input('last_name', 'text', $reg_errors); ?></p> <p><label for="username"><strong>Desired Username</strong></label><br /> <?php create_form_input('username', 'text', $reg_errors); ?> <small>Only letters and numbers are allowed.</small></p> <p><label for="email"><strong>Email Address</strong></label> <br /><?php create_form_input('email', 'text', $reg_errors); ?></p> <p><label for="pass1"><strong>Password</strong></label><br /> <?php create_form_input('pass1', 'password', $reg_errors); ?> <small>Must be between 6 and 20 characters long, with at least one lowercase letter, one uppercase letter, and one number.</small></p> <p><label for="pass2"><strong>Confirm Password</strong> </label><br /><?php create_form_input('pass2', 'password', $reg_errors); ?></p> <input type="submit" name="submit_button" value="Next →" id="submit_button" class="formbutton" /> </form> Thanks before Quote Link to comment https://forums.phpfreaks.com/topic/259664-cannot-redeclare-class/ Share on other sites More sharing options...
requinix Posted March 25, 2012 Share Posted March 25, 2012 For some reason you're including form_functions.inc.php more than once. Don't do that. Easy way to avoid it is to use require_once(). Quote Link to comment https://forums.phpfreaks.com/topic/259664-cannot-redeclare-class/#findComment-1330866 Share on other sites More sharing options...
andre25 Posted March 25, 2012 Author Share Posted March 25, 2012 For some reason you're including form_functions.inc.php more than once. Don't do that. Easy way to avoid it is to use require_once(). Thanks a lot.... How stupid I am... Quote Link to comment https://forums.phpfreaks.com/topic/259664-cannot-redeclare-class/#findComment-1330869 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.