PHP Classes

File: simple_example_add.php

Recommend this page to a friend!
  Classes of Manish Khanchandani  >  Ratings  >  simple_example_add.php  >  Download  
File: simple_example_add.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,742 bytes


Class file image Download
if($_POST['MM_Insert']==1) {
    try {
// including rating class
$Ratings = new Xoriant_Ratings();
// 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";
$return = $Ratings->showRating($_POST['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>Untitled Document</title>

<form id="form1" name="form1" method="post" action="">
  <?php echo $message; ?>
<p><?php for($i=1;$i<=10;$i++) { ?>
<input name="rating" type="radio" value="<?php echo $i; ?>" /> <?php echo $i; ?>
    <?php } ?>
    <input type="submit" name="Submit" value="Rate" />
  <p>User Id:
    <input name="user_id" type="text" id="user_id" value="1" size="32" />
  <p>Item Id:
    <input name="item_id" type="text" id="item_id" value="1" size="32" />
    <input name="rating_ip" type="text" id="rating_ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" size="32" />
    <input name="rating_date" type="text" id="rating_date" value="<?php echo date('Y-m-d H:i:s'); ?>" size="32" />
  <p>Unique IP:
    <input name="uniqueip" type="radio" value="1" />
<input name="uniqueip" type="radio" value="0" checked="checked" />
No </p>
  <p>Unique User:
    <input name="uniqueuser" type="radio" value="1" />
  <input name="uniqueuser" type="radio" value="0" checked="checked" />
    No </p>
    <input name="MM_Insert" type="hidden" id="MM_Insert" value="1" />
  <?php if($_POST) { ?>
<p>Current Rating: <?php echo $return['avg_rating']; ?></p>
  <?php } ?>

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