Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67411

Am i correctly trying to update a record in a database using PHP?

$
0
0

I'm trying to update a record in a database. The records and some fields are shown on a page in a table. Upon pressing the edit button next to a record in the webpage, it takes the user to a new page with where the information for that record is displayed on a new page with the data for that record inside textboxes.

Im not sure what the problem is, at first I thought it was the variable names, but I don't think so anymore.

<form action="../models/updateReview.php" method="POST">
  <div class="row">
    <div class="input-field">
      <input type="hidden" name="reviewId" value="<?php echo $indStmt['revid']; ?>">
    </div>
  </div>

  <div class="row">
    <div class="input-field">
      <input type="text" name="author" class="validate" value="<?php echo $indStmt['author']; ?>">
      <label class="author">Author</label>
    </div>
  </div>

  <div class="row">
    <div class="input-field">
      <input type="text" name="location" class="validate" value="<?php echo $indStmt['location']; ?>">
      <label class="location">Location</label>
    </div>
  </div>

  <div class="row">
    <div class="input-field">
      <input type="text" name="rating" class="validate" value="<?php echo $indStmt['rating']; ?>">
      <label class="rating">Rating(1-5)</label>
    </div>
  </div>

  <div class="row">
    <div class="input-field">
      <input type="text" name="review" class="validate" value="<?php echo $indStmt['review']; ?>">
      <label class="review">Review</label>
    </div>
  </div>

  <div class="row center">
    <button class="btn-large black" type="submit">Edit</button>
  </div>
</form>

<?php

$reviewId = trim(filter_input(INPUT_POST, 'reviewId', FILTER_SANITIZE_STRING));
$reviewName = trim(filter_input(INPUT_POST, 'author', FILTER_SANITIZE_STRING));
$reviewLocation = trim(filter_input(INPUT_POST, 'location', FILTER_SANITIZE_STRING));
$reviewRating = trim(filter_input(INPUT_POST, 'rating', FILTER_SANITIZE_STRING));
$reviewMessage = trim(filter_input(INPUT_POST, 'review', FILTER_SANITIZE_STRING));

if (empty($reviewName) || empty($reviewLocation) || empty($reviewRating) || empty($reviewMessage)){
    echo "Invalid Data Entry. Please check all field and try again";
}else {
    require('dbConnect.php');

    $statement = $connection->prepare('UPDATE tblreviews SET author = :author, location = :location, rating = :rating, review = :review WHERE revid = :reviewId');

    $statement->bindValue(':author', $reviewName);
    $statement->bindValue(':location', $reviewLocation);
    $statement->bindParam(':rating', $reviewRating);
    $statement->bindParam(':review', $reviewMessage);

    $statement->execute();

    header('Location: ../views/reviews.php');

}

?>


The first block of code is the form page that appears when the edit button is pressed. The second one is the process of me trying to update the actual record. It gets past the execute and takes users back to the main page as if it works, but the record isn't actually updated.


Viewing all articles
Browse latest Browse all 67411

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>