Results 1 to 5 of 5

Thread: Script for testimonials

  1. #1
    Join Date
    Feb 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Script for testimonials

    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

  2. #2
    Join Date
    Jan 2008
    Posts
    4,167
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Run this SQL:
    Code:
    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:
    Code:
    <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'>
      &nbsp;&nbsp;&nbsp;&nbsp;<b>".$row['name']." Says on ".date("F d, Y", $row['date'])." (with a ".$row['norp']." comment):</b><br /><br />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$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"/>&nbsp;Name<br />
    <input type="text" name="email"/>&nbsp;Email<br />
    <select name="norp">
    <option value="Positive">Positive</option>
    <option value="Negative">Negative</option>
    </select>
    &nbsp;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.
    Jeremy | jfein.net

  3. #3
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default problem with testimonial script

    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

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Apr 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you :-)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •