0

In trying to run a very simple update query - I get no errors; however, the rows do not update either. Here is the code:

try {
    require 'connect.php';

    $id = $_POST['id'];
    $rtn = $_POST['rtn'];
    $project_name = $_POST['project_name'];
    $staff_assigned = $_POST['staff_assigned'];
    $current_status = $_POST['current_status'];
    $start_date = $_POST['start_date'];
    $end_date = $_POST['end_date'];
    $building = $_POST['building'];
    $department = $_POST['department'];
    $department_contact = $_POST['department_contact'];
    $facilities_contact = $_POST['facilities_contact'];
    $device_count = $_POST['device_count'];
    $project_overview = $_POST['project_overview'];

    $sql = "UPDATE projects_list SET rtn=:rtn, project_name=:project_name, staff_assigned=:staff_assigned, current_status=:current_status, start_date=:start_date, end_date=:end_date, building=:building, department=:department, department_contact=:department_contact, facilities_contact=:facilities_contact, device_count=:device_count, project_overview=:project_overview WHERE id=:id";
    $stmt = $db->prepare($sql);

    $stmt->bindParam(':rtn', $rtn, PDO::PARAM_INT);
    $stmt->bindParam(':project_name', $project_name, PDO::PARAM_STR);
    $stmt->bindParam(':staff_assigned', $staff_assigned, PDO::PARAM_STR);
    $stmt->bindParam(':current_status', $current_status, PDO::PARAM_STR);
    $stmt->bindParam(':start_date', $start_date, PDO::PARAM_STR);
    $stmt->bindParam(':end_date', $end_date, PDO::PARAM_STR);
    $stmt->bindParam(':building', $building, PDO::PARAM_STR);
    $stmt->bindParam(':department', $department, PDO::PARAM_STR);
    $stmt->bindParam(':department_contact', $department_contact, PDO::PARAM_STR);
    $stmt->bindParam(':facilities_contact', $facilities_contact, PDO::PARAM_STR);
    $stmt->bindParam(':device_count', $device_count, PDO::PARAM_STR);
    $stmt->bindParam(':project_overview', $project_overview, PDO::PARAM_STR);
    $stmt->bindParam(':id', $id, PDO::PARAM_INT);

    $stmt->execute();

  }
  catch (PDOException $stmt) {
    echo $stmt->getMessage();
  }

Seems so simple; however, I have tried many different suggestions from many similar answers on Stack and/or Google and can't seem to nail this down. Any help is appreciated!

EDIT: Connection code:

try {
    $db = new PDO('mysql:host=localhost;dbname=projects;charset=utf8mb4', $user, $pass);

  } catch (PDOException $e) {
      print "Error!: " . $e->getMessage() . "<br/>";
      die();
  }
?>
sivs
  • 677
  • 1
  • 5
  • 11
  • 3
    Are you sure PDO is set up to throw exceptions? – jeroen Oct 25 '16 at 15:05
  • To add to what @jeroen is saying - show us your connection code. – Jay Blanchard Oct 25 '16 at 15:07
  • No it's not at the moment, I was printing PDO::errorInfo() and changed to try/catch back and forth to try and get some info... I am a straight n00b at PHP/PDO so any direction is appreciated! – sivs Oct 25 '16 at 15:07
  • Connection is fine. If I insert strings/ints into the values it updates fine so I believe it to be an issue with the bindParams – sivs Oct 25 '16 at 15:09
  • you've been asked about connection in regard of what is said in the first comment. so you have to ask PDO to report an error to you. Besides, [you shouldn't use try and catch to report PDO errors](https://phpdelusions.net/pdo#catch) – Your Common Sense Oct 25 '16 at 15:10
  • Ahhh, got ya @YourCommonSense. And that is set in the connection? PDO::ATTR_ERRMODE in the new PDO connection? – sivs Oct 25 '16 at 15:12
  • you can do it either way, in constructor or with setattribute – Your Common Sense Oct 25 '16 at 15:20

0 Answers0