Review System

Right.

review.php
Code:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

	<title>Review System</title>
	<link rel="stylesheet" type="text/css" href="style.css" />
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	
</head>

<body>

<?php

require 'config.php';

if (isset($_POST['title'])) {

$title = mysql_real_escape_string(strip_tags($_POST['title']));
$rating = mysql_real_escape_string(strip_tags($_POST['rating']));
$review = mysql_real_escape_string(strip_tags($_POST['review']));
$email = mysql_real_escape_string(strip_tags($_POST['email']));



// Form has been filled in, check input

if (empty($title) || empty($rating) || empty($review) || empty($email)) {

	echo "<div id='error'>";
	echo "You did not fill out the form correctly, please check:";
	echo "<ul>";
	echo "<li>You have entered a title</li>";
	echo "<li>You have selected a rating</li>";
	echo "<li>You have written a review</li>";
	echo "<li>You have entered an email address</li>";
	echo "</ul>";
	echo "</div>";
	echo "<br /><br />";
		
} else {


// Form input is ok, insert to database

mysql_query("INSERT INTO reviews(title,rating,review,email) VALUES('$title','$rating','$review','$email')") or die(mysql_error());

echo "<div id='success'>Your review was successfully submitted to the database!<br /><br /><a href='showreviews.php'>Back to the reviews page</a></div>";
echo "<br /><br />";

}
}


?>

<form action="review.php" method="post">

<div id="form">

	<p>Title:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="title" id="formtextbox" /></p>
	
	<p>Email:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="email" id="formtextbox" /></p>
	
	<p>Rating:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <select id="formdropdown" name="rating">
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
	<option value="4">4</option>
	<option value="5">5</option>
	</select></p>
	
	<p>Category: &nbsp;&nbsp;<select id="formdropdown" name="category">
			
	<?php
	
		$getcategories = mysql_query("SELECT * FROM categories") or die(mysql_error());
		
		while ($listcategories = mysql_fetch_array($getcategories)) {
		
		$category = $listcategories['category'];
		
		echo "<option value=$category>$category</option>";
			
		}
		
		?>
		
	</select></p>
		
	<p>Review:<br /><textarea name="review" id="formtextarea"></textarea></p><br />
		
	<p id="formbuttons"><input type="submit" value="Submit Review" class="formbutton" />&nbsp;&nbsp;<input type="reset" value="Reset" class="formbutton" /></p>
		
</div>
		
</form>

</body>

</html>

config.php
Code:
<?php

mysql_connect("host","user","password");
mysql_select_db("review_system");

?>

style.css
Code:
#error
{
	background-color: #a52a2a;
	
	font-family: verdana;
	font-size: 10px;
	color: #fff;
	font-weight: bold;
	
	text-align: left;
	
	margin: 0 auto;
	
	border: 2px solid #333;
	
	padding: 40px;
	margin: 0 auto;
	
	width: 500px;
	height: 100px;
}

#form
{
	font-family: verdana;
	font-size: 10px;
	color: #333;
	font-weight: bold;
	border: 1px solid #555;
	
	padding: 40px;
	margin: 0 auto;
	
	width: 500px;
	height: 400px;
}

#formtextbox
{
	width: 300px;
	height: 20px;
	
	font-family: verdana;
	font-size: 10px;
	color: #333;
	font-weight: bold;
}

#formdropdown
{
	width: 100px;
	height: 20px;
	
	font-family: verdana;
	font-size: 10px;
	color: #333;
	font-weight: bold;
}

#formtextarea
{
	width: 300px;
	height: 200px;
	
	font-family: verdana;
	font-size: 10px;
	color: #333;
	font-weight: bold;
	
	margin-left: 62px;
}

#formbuttons
{
	margin: 0 auto;
	text-align: center;
}

.formbutton
{
	width: 100px;
	height: 24px;
	
	font-family: verdana;
	font-size: 10px;
	color: #333;
	font-weight: normal;
	
	background-color: #e5e5e5;
	border: 1px solid #555;
	
	text-align: center;
}

#success
{
	background-color: #fff;
	
	font-family: verdana;
	font-size: 10px;
	color: #555;
	font-weight: bold;
	
	text-align: left;
	
	margin: 0 auto;
	
	border: 2px solid #333;
	
	padding: 40px;
	margin: 0 auto;
	
	width: 500px;
	height: 40px;
}

#reviews
{
	font-family: verdana;
	font-size: 12px;
	color: #555;
	font-weight: bold;
	
	text-align: left;
	
	width: 600px;
	height: auto;
	
	border: 1px solid #aaa;
	
	margin: 0 auto;
}

.reviewtitle
{
	float: left;
	width: 400px;

}

.reviewcategory
{
	float: right;
}

.reviewrating
{
	float: right;

}

showreviews.php
Code:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

	<title>Review System</title>
	<link rel="stylesheet" type="text/css" href="style.css" />
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	
</head>

<body>

<div id="reviews">

<a href="review.php">Add a Review</a>

<?php

require 'config.php';

$getreviews = mysql_query("SELECT * FROM reviews");

while ($listreviews = mysql_fetch_array($getreviews)) {

$title = $listreviews['title'];
$rating = $listreviews['rating'];
$review = $listreviews['review'];
$category = $listreviews['category'];

echo "<hr>";
echo "<div class='review'>";
echo "<div class='reviewtitle'>Title: $title</div><div class='category'>Category: $category</div><div class='rating'>Rating: $rating</div>";
echo "<hr>";
echo "<div class='review'>$review</div>";
echo "</div>";
echo "<hr>";
echo "<br /><br /><br /><br />";

}

?>

</div>

</body>
</head>
</html>

Right, before I start, the styling isn't great so I appologise for that :o

To start with you need to copy the text above into the filenames I have indicated via notepad (eg copy the top box into notepad and save it as review.php (make sure it's not .php.txt as it wont work) ) and copy them up to your web server. You need to edit config.php to contain your details to connect to the database but don't change the database name. Then, on phpmyadmin, you need to create a database called review_system. Then create two tables: reviews and categories

In the reviews table, you need to create the following fields:

id int(4) auto_imcrement primary key
title varchar(20)
rating int(1)
review varchar(500)
email varchar(50)
category varchar(15)

In the categories table, you need the following fields:

id int(1) auto_increment primary key
category varchar(15)


To add categories to it, you just need to insert rows into the categories table and just increment the id youself eg

id category

1 xbox
2 ps2
3 nintendo
4 sega

... and so on :) Just make sure to get someone to check it over (Probably best creating a new thread for it :))

Hope that helps :cool:
 
Last edited:
No problem :) Just in case you haven't noticed, the user has to submit their email address when writing a review but this is not displayed on the showreviews.php page but if you view the database directly you will see the email address which could be useful if you need to contact anyone who submitted a review :)
 
Just another note, I haven't been able to test it in IE as I only have access to firefox so if the layout is all messed up, let me know and i'll try and look at it sometime :)
 
Just change this line in config.php

Code:
mysql_select_db("1583_review");

You then need to create a table called 'reviews' and one called 'categories' :)

Anyway, what happened to getting someone to check it? I meant you need to get someone to look at the source code ;)
 
Trigger said:
In the reviews table, you need to create the following fields:

id int(4) auto_imcrement primary key
title varchar(20)
rating int(1)
review varchar(500)
email varchar(50)
category varchar(15)

In the categories table, you need the following fields:

id int(1) auto_increment primary key
category varchar(15)


To add categories to it, you just need to insert rows into the categories table and just increment the id youself eg

id category

1 xbox
2 ps2
3 nintendo
4 sega

... and so on :) Just make sure to get someone to check it over (Probably best creating a new thread for it :))

Hope that helps :cool:

do you have the sql query for this :confused:

and the styling doesnt matter tbh m8 ;)
 
I've never really had much success doing it that way- causes too many problems with different versions of MySQL and PHP-MyAdmin etc. It only took me 2 mins at most to create those tables though :)
 
Ok.

1.) Create a database called review_system (Or whatever you decided to call it, just edit config.php accordingly)

2.) Create a table called 'reviews' (Without the quotes) and give it 6 fields

3.) When it asks you to name the fields, give them these names with the following values (The number in brackets after the type is the length and needs to be entered manually) :

id int(4) auto_imcrement primary key (You need to select auto_increment from the drop down and tick the primary key box)
title varchar(20)
rating int(1)
review varchar(500)
email varchar(50)
category varchar(15)

4.) Save that table and create a new one called 'categories' without the quotes

5.) Set the number of fields to 2 and call them this just like above

id int(1) auto_increment primary key
category varchar(15)

6.) Save that table

EDIT: You will probably need to change the 'host' bit of config.php to 'localhost' :)
 
sql query is:

CREATE TABLE `users` (
`id` INT( 10 ) NOT NULL ,
`title` VARCHAR( 20 ) NOT NULL ,
`rating` INT( 1 ) NOT NULL ,
`review` VARCHAR( 500 ) NOT NULL ,
`email` VARCHAR( 50 ) NOT NULL ,
`category` VARCHAR( 15 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM ;
 
Go into the categories table, select insert, give the id '1' and then name the category, then give the next category '2' and name it and so on... :)
 
how do i make it show upto 5000 characters on the showreviews.php page :confused:

EDIT : ive managed to get all characters to show theres just no paragraph spaces
 
Last edited:
Back
Top Bottom