Jump to content

Not too sure why this Prepared Statement isn't working...


HelloJoe

Recommended Posts

For some reason this just isn't inserting...

 

HTML snippet:

<form name="testimonials_form" method="post" action="insert/">

Name
<input type="text" name="from" maxlegnth="100" />

Location
<input type="text" name="where" maxlegnth="100" />

Text Snippet
<input type="text" name="text" maxlegnth="255">

<input type="submit" name="submit" value="Continue" />

</form>

 

PHP Snippet:

<?php

$from = $_POST['from'];
$where = $_POST['where'];
$text = $_POST['text'];

if (!$from || !$where || !$text) {

  $error = "You have missed some fields.";
  $solution = "Please go back and <a href=\"javascript:history.go(-1)\" target=\"_self\">try again</a>.";

} else {

  $data_array =	array( ':from' => $from, ':where' => $where, ':text' => $text);

  $insert_testimonial = $connect->prepare("INSERT INTO `testimonials` (text, from, where) VALUES (:text, :from, :where)");

  $insert_testimonial->execute($data_array);
  
  $amount = $insert_testimonial->rowCount();

  if ($amount < 1) {

    $error = "Something went wrong.";
    $solution = "Please go back and <a href=\"javascript:history.go(-1)\" target=\"_self\">try again</a>.";

  } else {

    header ("Location: ../");

  }

}

?>

 

All I keep getting back is my custom error "Something went wrong." so there's no 500 error (internal server error) and if I echo $from, $where and $text it displays what I typed in the form, I've re-written it about 5 times in case I wrote it wrong or something but still no luck. I know there can't be a symbol missing or in the wrong place since it would return a 500 error.

 

Does anyone have any clue as to what's up with it? I've written codes like this countless times but this just doesn't seem to be working, so I must be missing something.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.