How to Create a Review Page in Php

The star rating and review systems are very common in eCommerce websites to allow customers to give reviews on products. The five star rating systems are very popular in which users can rate products past selecting stars from one to five and also give feedback comments. And then if yous're looking for script to implement rating and review system, and then you're here at right place. In this tutorial, you volition acquire how to develop v kickoff rating and review organization using Ajax, PHP and MySQL. We volition encompass this tutorial in piece of cake steps to create live example of 5 star rating system with Ajax, PHP and MySQL.

Besides, read:

  • Build Invoice System with PHP & MySQL
  • Build Live Conversation System with Ajax, PHP & MySQL
  • Build Comment System with Ajax, PHP & MySQL

As we will embrace this tutorial with live case to develop 5 kickoff rating and review organization using Ajax, PHP and MySQL, and so the major files for this case is following.

  • alphabetize.php
  • rating.js
  • saveRating.php

Step1: Create Database Table
First we will create MySQL database table item_rating to shop rating details and feedback comments.
CREATE Tabular array `item_rating` (
`ratingId` int(11) NOT NULL,
`itemId` int(11) Not Zero,
`userId` int(xi) NOT Null,
`ratingNumber` int(eleven) Not NULL,
`title` varchar(255) COLLATE utf8_unicode_ci Non Nada,
`comments` text COLLATE utf8_unicode_ci NOT NULL,
`created` datetime Non NULL,
`modified` datetime Non NULL,
`status` tinyint(1) Non NULL DEFAULT '1' COMMENT '1 = Block, 0 = Unblock'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
ALTER Tabular array `item_rating`
Add together Principal Cardinal (`ratingId`);

Step2: Create Rating and Review Class
In alphabetize.php file, we will create rating and review class with five start and inputs to save users rating and reviews.
<div class="row">
<div class="col-sm-12">
<form id="ratingForm" method="Mail">
<div grade="class-group">
<h4>Charge per unit this product</h4>
<button type="push button" class="btn btn-warning btn-sm rateButton" aria-characterization="Left Marshal">
<span class="glyphicon glyphicon-star" aria-subconscious="true"></span>
</button>
<button blazon="button" grade="btn btn-default btn-grey btn-sm rateButton" aria-label="Left Align">
<span class="glyphicon glyphicon-star" aria-hidden="truthful"></span>
</button>
<button blazon="button" class="btn btn-default btn-grey btn-sm rateButton" aria-label="Left Marshal">
<span class="glyphicon glyphicon-star" aria-subconscious="true"></span>
</button>
<button type="push button" course="btn btn-default btn-grey btn-sm rateButton" aria-characterization="Left Align">
<span grade="glyphicon glyphicon-star" aria-hidden="truthful"></span>
</push button>
<button blazon="push button" class="btn btn-default btn-grey btn-sm rateButton" aria-label="Left Align">
<bridge class="glyphicon glyphicon-star" aria-hidden="true"></span>
</button>
<input type="hidden" class="form-control" id="rating" name="rating" value="i">
<input type="hidden" class="form-command" id="itemId" name="itemId" value="12345678">
</div>
<div class="course-group">
<label for="usr">Title*</label>
<input type="text" class="course-control" id="title" name="title" required>
</div>
<div class="form-group">
<label for="comment">Comment*</label>
<textarea class="grade-control" rows="five" id="comment" proper name="annotate" required></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-info" id="saveReview">Salve Review</push> <push type="button" class="btn btn-info" id="cancelReview">Abolish</push>
</div>
</form>
</div>
</div>

Step3: Rating and Review Form Submit and Save with jQuery Ajax
In rating.js file, nosotros will handle Course submit with jQuery and likewise handle Form values save functionality by making Aajx asking to saveRating.php to save rating details to database table.
$('#ratingForm').on('submit', function(event){
event.preventDefault();
var formData = $(this).serialize();
$.ajax({
type : 'POST',
url : 'saveRating.php',
data : formData,
success:office(response){
$("#ratingForm")[0].reset();
window.setTimeout(role(){window.location.reload()},1000)
}
});
});

Step4: Salvage Rating and Review into Database Table
Now in saveRating.php file, we volition handle functionality to save rating and review details in to MySQL database tabular array item_rating. Here we have hard coded itemId and userId. You lot tin implement it dynamically in your system according to your needs.
<?php
include_once("db_connect.php");
if(!empty($_POST['rating']) && !empty($_POST['itemId'])){
$itemId = $_POST['itemId'];
$userID = 1234567;
$insertRating = "INSERT INTO item_rating (itemId, userId, ratingNumber, title, comments, created, modified) VALUES ('".$itemId."', '".$userID."', '".$_POST['rating']."', '".$_POST['title']."', '".$_POST["annotate"]."', '".date("Y-grand-d H:i:s")."', '".date("Y-m-d H:i:s")."')";
mysqli_query($conn, $insertRating) or die("database error: ". mysqli_error($conn));
echo "rating saved!";
}
?>

Step5: Display Rating and Review Details
In index.php file, we volition display users saved rating and review details from database table item_rating with users star rating to brandish rating star as selected .

<div class="row">
<div course="col-sm-7">
<hour/>
<div class="review-block">
<?php
$ratinguery = "SELECT ratingId, itemId, userId, ratingNumber, championship, comments, created, modified FROM item_rating";
$ratingResult = mysqli_query($conn, $ratinguery) or die("database mistake:". mysqli_error($conn));
while($rating = mysqli_fetch_assoc($ratingResult)){
$engagement=date_create($rating['created']);
$reviewDate = date_format($appointment,"G d, Y");
?>
<div class="row">
<div course="col-sm-iii">
<img src="paradigm/contour.png" class="img-rounded">
<div course="review-block-name">By <a href="#">phpzag</a></div>
<div class="review-block-appointment"><?php echo $reviewDate; ?></div>
</div>
<div form="col-sm-ix">
<div class="review-block-charge per unit">
<?php
for ($i = ane; $i <= v; $i++) {
$ratingClass = "btn-default btn-grey";
if($i <= $rating['ratingNumber']) {
$ratingClass = "btn-alert";
}
?>
<button type="button" grade="btn btn-xs <?php echo $ratingClass; ?>" aria-characterization="Left Align">
<span class="glyphicon glyphicon-star" aria-hidden="true"></span>
</button>
<?php } ?>
</div>
<div class="review-block-title"><?php echo $rating['championship']; ?></div>
<div class="review-block-description"><?php repeat $rating['comments']; ?></div>
</div>
</div>
<hr/>
<?php } ?>
</div>
</div>
</div>

You may too like:

  • Build Live Chat System with Ajax, PHP & MySQL
  • Create Effect Calendar with jQuery, PHP and MySQL
  • Build Invoice System with PHP & MySQL
  • Button Notification Organisation with PHP & MySQL
  • Create Bootstrap Cards with PHP and MySQL
  • Build Content Direction Arrangement with PHP & MySQL
  • Catechumen Unix Timestamp To Readable Date Time in PHP
  • Ajax Drop Downward Option Data Load with PHP & MySQL
  • Inventory Direction System with Ajax, PHP & MySQL
  • Drag and Drop File Upload using jQuery and PHP
  • Load Dynamic Content in Bootstrap Popover with Ajax, PHP & MySQL

Y'all can view the live demo from the Demo link and can download the script from the Download link below.
Demo Download

woodwonscalun1943.blogspot.com

Source: https://www.phpzag.com/star-rating-system-with-ajax-php-and-mysql/

0 Response to "How to Create a Review Page in Php"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel