View Full Version : Script for testimonials
TheStar
02-05-2009, 01:14 AM
I am trying to put a testimonials section on my site and want people to be able to see their testimonial after submitting. Sort of like posting comments.
I already have the code to the basics like name, text area and submit button. I want the testimony to automatically post to my site after it's submitted instead of adding it manually
Is there a free script or code for testimonials?
Thanks :D
Run this SQL:
CREATE TABLE IF NOT EXISTS `testimonials` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(40) NOT NULL,
`email` varchar(60) NOT NULL,
`text` text NOT NULL,
`norp` varchar(9) NOT NULL COMMENT 'Positive or Negative',
`date` varchar(30) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
And testimonial.php:
<style type="text/css">
input, textarea {
border: none;
border-bottom: 3px solid orange;
margin-bottom: 5px;
background: #FFF;
}
input, select {
width: 150px
}
input:hover, textarea:hover {
border-bottom: 3px solid #3845C1;
}
textarea, input[type='submit'] {
border-top: 1px solid grey;
border-right: 1px solid grey;
border-left: 1px solid grey;
font-family: arial;
font-size: 11px;
}
</style>
<?php
mysql_connect('localhost', 'root', '') or die("MySQL Error!<br>(".mysql_error().")<br>Could not proceed");
mysql_select_db('testing');
if(isset($_POST['submit'])){
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['comment'])) {
die("Forget to fill something in?");
}
$_POST['comment'] = addslashes($_POST['comment']);
mysql_query("INSERT INTO `testimonials`
(`name`,`email`,`text`,`norp`,`date`) VALUES ('".$_POST['name']."', '".$_POST['email']."', '".$_POST['comment']."', '".$_POST['norp']."', '".time()."')")or die("MySQL Error!<br>(".mysql_error().")<br>Could not proceed");
header("Location: ".$_SERVER['PHP_SELF']);
}
$query = mysql_query("SELECT * FROM `testimonials` ORDER BY `id`");
$i = 0;
echo "<h3>Testimonials</h3><div style='width: 500px'>";
while($row = mysql_fetch_assoc($query)){
$i = ($i == 2) ? 0 : 1;
$bg = ($i == 1) ? "background-color: lightgrey;" : "background-color: #FFF;";
echo "
<p style='".$bg." margin: 0; padding: 5px 0 0 0; height: 100px; font-family: arial; border-bottom: 1px solid black'>
<b>".$row['name']." Says on ".date("F d, Y", $row['date'])." (with a ".$row['norp']." comment):</b><br /><br />
".$row['text']."
</p>";
}
?>
<br />
<div style="font-family: arial;font-size: 11px;">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="name"/> Name<br />
<input type="text" name="email"/> Email<br />
<select name="norp">
<option value="Positive">Positive</option>
<option value="Negative">Negative</option>
</select>
Positive or Negative(both excepted)<br />
Comment:<br />
<textarea style="height: 200px;width: 500px;" name="comment"></textarea><br />
<input type="submit" name="submit" value="Submit Testimonial!" />
</form>
</div>
Change the highlighted to your details.
jd201263
04-25-2012, 12:07 PM
Hia,
ive upload this script and when i click to go to page i get this error-
MySQL Error!
(Access denied for user 'http://www.rtdm.'@'localhost' (using password: NO))
Could not proceed
in the script where instructd to place own details - localhost and root im not quite sure ii ive put the correct info here, what exactly do i place in these areas, im fairly new to this so pls excuse my ignorance, thanx in advance,
Jd :)
djr33
04-26-2012, 06:58 AM
You don't have permissions to use/modify your MySQL database. I don't think it's a problem in this script.
Also, as a general option, realize that you can use any "guestbook" script in this way, if you just change the labels.
jd201263
05-03-2012, 02:26 PM
Thank you :-)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.