<!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: <input type="text" name="title" id="formtextbox" /></p>
<p>Email: <input type="text" name="email" id="formtextbox" /></p>
<p>Rating: <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: <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" /> <input type="reset" value="Reset" class="formbutton" /></p>
</div>
</form>
</body>
</html>
<?php
mysql_connect("host","user","password");
mysql_select_db("review_system");
?>
#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;
}
<!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>
mysql_select_db("1583_review");
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 onJust make sure to get someone to check it over (Probably best creating a new thread for it
)
Hope that helps![]()
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 ;