Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/259664-cannot-redeclare-class/
Share on other sites

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.