php - PDO will not insert to MYSQL DB Invalid parameter number: parameter was not defined -
warning: pdostatement::execute() [pdostatement.execute]: sqlstate[hy093]: invalid parameter number: parameter not defined
<?php $firstname = $_post['first-name']; $lastname = $_post['last-name']; $company = $_post['company']; $email = $_post['email']; $phone = $_post['phone']; $city = $_post['city']; $state = $_post['state']; $zip = $_post['zip']; $country = $_post['country']; $type = $_post['type']; $source = "ip-demo"; // query $sql = "insert contact (first-name,last-name,company,email,phone,city,state,zip,country,type,source) values (:first-name,:last-name,:company,:email,:phone,:city,:state,:zip,:country,:type,:source)"; $q = $conn->prepare($sql); $q->execute(array( ':first-name'=>$firstname, ':last-name'=>$lastname, ':company'=>$company, ':email'=>$email, ':phone'=>$phone, ':city'=>$city, ':state'=>$state, ':zip'=>$zip, ':country'=>$country, ':type'=>$type, ':source'=>$source ));
your query contains several object names need backtick quoting, @ least these:
first-name
last-name
type
edit: btw, tried code , prepare()
failed:
php fatal error: uncaught exception 'pdoexception' message 'sqlstate[42000]: syntax error or access violation: 1064 have error in sql syntax; check manual corresponds mysql server version right syntax use near '-name,last-name,company,email,phone,city,state,zip,country,type,source)
Comments
Post a Comment