PHP Classes

File: example_yesno.php

Recommend this page to a friend!
  Classes of Manish Khanchandani  >  Ratings  >  example_yesno.php  >  Download  
File: example_yesno.php
Role: Example script
Content type: text/plain
Description: Example
Class: Ratings
Store and retrieve ratings of products in MySQL
Author: By
Last change:
Date: 13 years ago
Size: 2,643 bytes


Class file image Download

= $_GET['item_id'];
$item_id) $item_id = 100;
// including rating class
$Ratings = new Xoriant_Ratings();
try {
$_POST['MM_Insert']==1) {
// making array of results
$data['user_id'] = $_POST['user_id'];
$data['item_id'] = $_POST['item_id'];
$data['rating'] = $_POST['rating'];
$data['rating_ip'] = $_POST['rating_ip'];
$data['rating_date'] = $_POST['rating_date'];
$data['uniqueip'] = $_POST['uniqueip'];
$data['uniqueuser'] = $_POST['uniqueuser'];
// validating the data
$data['uniqueip']=="1") {
$count = $Ratings->checkRatingUniqueIp($data);
$count>0) throw new Exception("Duplicate Ip");
$data['uniqueuser']=="1") {
$count = $Ratings->checkRatingUniqueUser($data);
$count>0) throw new Exception("Duplicate User");
// inserting data in table
$rating_id = $Ratings->phpinsert('xoriant_ratings', 'rating_id', $data);
// return message
$message = "Rating Submitted Successfully";
} catch (
exception $e) {
$errorMessage = $e->getMessage();
$message = $errorMessage;
try {
$return = $Ratings->showRating($item_id);
} catch (
exception $e) {
$errorMessage = $e->getMessage();
$message = $errorMessage;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Rating Demo</title>

<form id="form1" name="form1" method="post" action="">
  <h1>Rate for Item <?php echo $item_id; ?></h1>
  <?php echo $message; ?>
<p><input name="rating" type="radio" value="1" /> Yes <input name="rating" type="radio" value="0" /> No
    <input type="submit" name="Submit" value="Rate" />
    <input name="user_id" type="hidden" id="user_id" value="1" size="32" />
    <input name="item_id" type="hidden" id="item_id" value="<?php echo $item_id; ?>" size="32" />
    <input name="rating_ip" type="hidden" id="rating_ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" size="32" />
    <input name="rating_date" type="hidden" id="rating_date" value="<?php echo date('Y-m-d H:i:s'); ?>" size="32" />
    <input name="uniqueip" type="hidden" id="uniqueip" value="0" size="32" />
    <input name="uniqueuser" type="hidden" id="uniqueuser" value="0" size="32" />
    <input name="MM_Insert" type="hidden" id="MM_Insert" value="1" />
  <p>Current rating for this Item: <?php echo $return['avg_rating']; ?></p>

For more information send a message to info at phpclasses dot org.