My Query:
$query = 'INSERT INTO ptd_users (username,contact,email,longitude,latitude,state,city,address) values (?,?,?,?,?,?,?,?)';
$q = $conn->prepare($query);
$q->execute($_POST['user']);
Result of print_r($_POST[user]) :
Array ( [name] => marc [contact] => 123456789 [email] => [email protected] [longitude] => 12.3786085 [latitude] => 96.6126145 [state_select] => Arizona [city_select] => sussex [address] => address details )
I'm getting the following error while executing the query:
PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
$q->execute(array($_POST['user']['name'], $_POST['user']['contact'], ..., $_POST['user']['address']));Replace this...with the rest of your $_POST :)$_POST['user']$q->execute($myArray);method. And, if your expected some other types then juststrings, its a good pratice tobindthem like$conn->bindParam(2, $_POST['user']['contact'],PDO::PARAM_INT);But @Rizier123 example gives you a better perspective :)