Hi
I am trying to add checkboxes to a registration form I am doing for a client and need to add multiple checkbox values to a database using php and pdo but am not 100% on pdo and know I done it wrong as I get the following error when clicking the submit button
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
Below is my code
UPDATE: I think the issue in this section of codingCode://insert into database with a prepared statement $stmt = $db->prepare('INSERT INTO members (username,password,email,drivers,active) VALUES (:username, :password, :email, :drivers, :active)'); $stmt->execute(array( ':username' => $_POST['username'], ':password' => $hashedpassword, ':email' => $_POST['email'], $drivers => implode(', ', $_POST['drivers']), ':active' => $activasion )); $id = $db->lastInsertId('memberID'); $title = "Register"; include ( 'includes/header.php' ); ?> <!--CONTENT--> <!-- Page Title --> <div class="section section-breadcrumbs"> <div class="container"> <div class="row"> <div class="col-md-12"> <h1>Register</h1> </div> </div> </div> </div> <div class="section"> <div class="container"> <div class="row"> <div class="col-sm-12"> <div class="basic-login"> <form role="form" method="post" action="" autocomplete="off"> <h2>Please Sign Up</h2> <p>Already a member? <a href='login.php'>Login</a></p> <hr> <?php //check for any errors if(isset($error)){ foreach($error as $error){ echo '<p class="bg-danger">'.$error.'</p>'; } } //if action is joined show sucess if(isset($_GET['action']) && $_GET['action'] == 'joined'){ echo "<h2 class='bg-success'>Registration successful, please check your email to activate your account.</h2>"; } ?> <div class="form-group"> <input type="text" name="username" id="username" class="form-control input-lg" placeholder="User Name" value="<?php if(isset($error)){ echo $_POST['username']; } ?>" tabindex="1"> </div> <div class="form-group"> <input type="email" name="email" id="email" class="form-control input-lg" placeholder="Email Address" value="<?php if(isset($error)){ echo $_POST['email']; } ?>" tabindex="2"> </div> <div class="row"> <div class="col-xs-6 col-sm-6 col-md-6"> <div class="form-group"> <input type="password" name="password" id="password" class="form-control input-lg" placeholder="Password" tabindex="3"> </div> </div> <div class="col-xs-6 col-sm-6 col-md-6"> <div class="form-group"> <input type="password" name="passwordConfirm" id="passwordConfirm" class="form-control input-lg" placeholder="Confirm Password" tabindex="4"> </div> </div> <div class="col-xs-6 col-sm-6 col-md-6"> <div class="form-group"> <input type="checkbox" name="drivers[]" value="jasonplato"> Jason Plato <br> <input type="checkbox" name="drivers[]" value="ashsutton"> Ash Sutton <br> <input type="checkbox" name="drivers[]" value="joshcook"> Josh Cook <br> </div> </div> </div> <div class="row"> <div class="col-xs-6 col-md-6"><input type="submit" name="submit" value="Register" class="btn btn-primary btn-block btn-lg" tabindex="5"></div> </div> </form> </div> </div> </div> </div> </div> <?php include( 'includes/footer.php' ); ?>
the error seems to be on line 74 which is belowCode:$stmt->execute(array( ':username' => $_POST['username'], ':password' => $hashedpassword, ':email' => $_POST['email'], $drivers => implode(', ', $_POST['drivers']), ':active' => $activasion ));
Can anyone help please, thank you in advanceCode:$drivers => implode(', ', $_POST['drivers']),



Reply With Quote
Bookmarks