2

Before I begin, I know there are other questions just like this, but I couldn't derive a solution from any of those. My code was working fine until I deleted it accidentally, and then had to remake it.

$sql    = "INSERT INTO inquiries (name, email, phone, date, message, event-type, guests, event-budget) VALUES (:name, :email, :phone, :date, :message, :event-type, :guests, :event-budget)";
$stmt   = $pdo->prepare($sql);
$result = $stmt->execute(array( ':name' => $_POST['name'],
                                ':email' => $_POST['email'],
                                ':phone' => $_POST['phone'],
                                ':date' => $_POST['date'],
                                ':message' => $_POST['message'],
                                ':event-type' => $_POST['event-type'],
                                ':guests' => $_POST['guests'],
                                ':event-budget' => $_POST['event-budget']
                               ));
if($result) {
    $tpl->define("alert", "<div class='col-md-12'><div class='alert-success' style='margin-left: 0; margin-bottom: 20px;'><h3><img src='http://criesvals-mbp.home:5757/_zip/_templates/_front/Refresh/multi-page/assets/images/head_img1.png' alt='' class='pull-left small_design_left'>Your Appointment Has Been Submitted<img src='http://criesvals-mbp.home:5757/_zip/_templates/_front/Refresh/multi-page/assets/images/head_img1.png' alt='' class='pull-right small_design_right'></h3></div></div>");
    $tpl->define('hide', 'style="display: none;"');
} else {
    $tpl->define("alert", "<div class='col-md-12'><div class='alert-failure' style='margin-left: 0; margin-bottom: 20px;'><h3><img src='http://criesvals-mbp.home:5757/_zip/_templates/_front/Refresh/multi-page/assets/images/head_img1.png' alt='' class='pull-left small_design_left'>There was an error submitting your appointment. Please try again later.</h3><img src='http://criesvals-mbp.home:5757/_zip/_templates/_front/Refresh/multi-page/assets/images/head_img1.png' alt='' class='pull-right small_design_right'></div>");
    $tpl->define('hide', 'style="display: none;"');
}
Intact Dev
  • 486
  • 3
  • 7
  • 16
  • Check if all POST are set before binding – Mihai Jan 27 '15 at 21:11
  • @Mihai I just double checked, and they're all indeed set. I also have if statements checking if they're "isset" & "!empty". – Intact Dev Jan 27 '15 at 21:15
  • 5
    try to change parameter names with dashes `:event-type` to no-dashes names `:eventType` etc... – Alex Jan 27 '15 at 21:18
  • @KimAlexander that worked, but now I have a syntax error in my query. Any idea as to what it can be? – Intact Dev Jan 27 '15 at 21:23
  • 2
    `message, "event-type", guests,` etc... that is just bad habit to name columns with dashes... maybe it is much easier for you and much better for future to rename columns... – Alex Jan 27 '15 at 21:24
  • 3
    @Mihai I agree it's surely related, but how could it be a duplicate if the OP does not know where the error comes from ? – slaur4 Jan 27 '15 at 21:26
  • @KimAlexander Thanks so much for your help. I would appreciate you submit an answer so you can get the points you deserve. – Intact Dev Jan 27 '15 at 21:32
  • It is duplicated because it is the same problem.What has knowing or not knowing about the problem has to do with being a duplicate?If he doesnt know its not a duplicate but as soon as he knows it becomes a duplicate?A bit of logic,please.And for the record,I upvoted the question. – Mihai Jan 27 '15 at 21:42
  • Rather than posting a screenshot of the error, please put it into the question as plaintext so that anyone else Googling to find that text can find this question. – Andy Lester Jan 27 '15 at 21:44
  • MySQL is interpreting two of your columns as "column_1 **MINUS** column_2" – Funk Forty Niner Jan 27 '15 at 21:47
  • Mihai, I'm glad that you feel concerned about my logic. Still, I don't see how the question "How can I handle PDOException Invalid parameter number" is a duplicate of "Which characters are valid for PDO placeholders". The answer to the second one induce the answer to the first, and your link indeed is very useful. But they're not the same. Anyway I was not picking a fight, I was questionning the use of "duplicate" term to point out that this question can be helpful. – slaur4 Jan 27 '15 at 22:36
  • @slaur4 I agree with you; both questions are related but they definitely aren't duplicates. – Intact Dev Jan 28 '15 at 13:00

1 Answers1

2

try to change parameter names with dashes :event-type to no-dashes names :eventType etc...

and probably message, "event-type", guests, ... etc

you are very welcome! :-)

Alex
  • 16,739
  • 1
  • 28
  • 51