简体   繁体   中英

Message: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

The following code is producing an exception at $stmt->execute();

This is a new issue, I have gone through other listings with this error and the issues identified are cleared here. Is this a new issue to be reported with Slim? Any idea what else it could be? Many thanks, this has turned out to be a 2 day problem. I'm code-blind atm.


$gender             = $_POST['gender'];
$firstName          = $_POST['firstName'];
$lastName           = $_POST['lastName'];
$age                = $_POST['age'];
$phone              = $_POST['phone'];
$contactPreference  = $_POST['contactPreference'];
$city               = $_POST['city'];
$state              = $_POST['state'];
$country            = $_POST['country'];
$zip                = $_POST['zip'];
$adType             = $_POST['adType'];
$activity           = $_POST['activity'];
$whenDate           = $_POST['whenDate'];
$providerGender     = $_POST['providerGender'];
$providerAge        = $_POST['providerAge'];
$providerOffer      = $_POST['providerOffer'];

$db = new PDO( "mysql:host=$server;dbname=$dbname;charset=utf8", $username, $password);
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$stmt = $db->prepare(
    'INSERT INTO customers (
                    gender,
                    firstName,
                    lastName,
                    age,
                    phone,
                    contactPreference,
                    city,
                    state,
                    country,
                    zip,
                    adType,
                    activity,
                    whenDate,
                    providerGender,
                    providerAge,
                    providerOffer
                    )
                VALUES (
                    :gender,
                    :firstName,
                    :lastName,
                    :age,
                    :phone,
                    :contactPreference,
                    :city,
                    :state,
                    :country,
                    :zip,
                    :adType,
                    :activity,
                    :whenDate,
                    :providerGender,
                    :providerAge,
                    :providerOffer
                    );'
);

$stmt->bindParam(':gender', $gender );
$stmt->bindParam(':firstName', $firstName );
$stmt->bindParam(':lastName', $lastName );
$stmt->bindParam(':age', $age );
$stmt->bindParam(':phone', $phone );
$stmt->bindParam(':contactPreference', $contactPreference );
$stmt->bindParam(':city', $city );
$stmt->bindParam(':state', $state );
$stmt->bindParam(':country', $country );
$stmt->bindParam(':zip', $zip );
$stmt->bindParam(':adType:', $adType );
$stmt->bindParam(':activity', $activity );
$stmt->bindParam(':whenDate', $whenDate );
$stmt->bindParam(':providerGender', $providerGender );
$stmt->bindParam(':providerAge', $providerAge );
$stmt->bindParam(':providerOffer', $providerOffer );

$stmt->execute();

Extra : at $stmt->bindParam(':adType:', $adType );

It would be

$stmt->bindParam(':adType', $adType );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM