Results 1 to 1 of 1

Thread: php pdo checkboxes insert

  1. #1
    Join Date
    May 2012
    Posts
    216
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default php pdo checkboxes insert

    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

    Code:
    			//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' ); ?>
    UPDATE: I think the issue in this section of coding

    Code:
    $stmt->execute(array(
    				':username' => $_POST['username'],
    				':password' => $hashedpassword,
    				':email' => $_POST['email'],	
    				$drivers => implode(', ', $_POST['drivers']),
    				':active' => $activasion
    			));
    the error seems to be on line 74 which is below

    Code:
    $drivers => implode(', ', $_POST['drivers']),
    Can anyone help please, thank you in advance
    Last edited by ianhaney; 04-03-2017 at 06:07 PM.

Similar Threads

  1. about checkboxes...
    By Piotto in forum PHP
    Replies: 0
    Last Post: 11-15-2009, 09:22 AM
  2. Resolved disable other checkboxes if 3 checkboxes are checked
    By al3bed in forum JavaScript
    Replies: 1
    Last Post: 08-28-2009, 04:41 PM
  3. Checkboxes
    By Medyman in forum Looking for such a script or service
    Replies: 10
    Last Post: 07-19-2007, 02:39 AM
  4. Disable checkboxes based in other checkboxes.
    By gastongr in forum JavaScript
    Replies: 11
    Last Post: 04-24-2006, 11:42 PM
  5. Checkboxes
    By kermit_cof in forum JavaScript
    Replies: 3
    Last Post: 09-19-2005, 11:12 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •