Solved

PHP Code required for the adding a user commnets in a page.

Posted on 2008-10-17
3
200 Views
Last Modified: 2012-05-05
Hi Guys,

I am Looking towards someone to come foward and help me in this regard.
I am just develpping a website for my resturant. I want to include a Feedback page developed in PHP.
What i looks into the page. i dont want, when use submitt their feedback, then script generate an email to our email address but i also wants its added these comments on that page too. Just like in blog when you left the comments its added into the bottom of the page.
SO please if anyone can help. i found the some code but those only send email not adding the comment in the same page.
0
Comment
Question by:waqas105
3 Comments
 
LVL 15

Accepted Solution

by:
MMDeveloper earned 250 total points
Comment Utility
This is a relatively broad scope of work and there isn't a 'single answer solution' to achieve this.


First you need the site to be database driven in some form. You need a script that reads a database for 'comments' that pertain to a specific page. I'm not sure if this will be like a forum where different pages have their own respective comments, or all comments are dumped onto one page. Either way, the script simply grabs all relevant comments from the database, and uses PHP to format them into HTML content.


Your 'feedback form' will simply post to another PHP script that simply sanitizes the user input (to prevent SQL injection) and posts it into the same database for comments.

That's pretty much it unless you later want to put in administration features such as comment deletion, comment approval, etc. Once the form submits to the database, the original script mentioned previously will automatically pull the results from the database upon page load, and display them on the page.
0
 
LVL 1

Assisted Solution

by:levio
levio earned 250 total points
Comment Utility
This would be the html part of it

<form id="contact" method="post" action="sendemail.php" style="position: relative; z-index: 1;">

            <!-- DO NOT change ANY of the php sections -->
            <?php
            $ipi = getenv("REMOTE_ADDR");
            $httprefi = getenv ("HTTP_REFERER");
            $httpagenti = getenv ("HTTP_USER_AGENT");
            ?>

            <input type="hidden" name="ip" value="<?php echo $ipi ?>" />
            <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
            <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />


            Name:<br />
            <input type="text" name="visitor" size="35" />
            <br />
            Email:<br />
            <input type="text" name="visitormail" size="35" />
            <br />
            Subject:<br />
            <input type="text" name="attn" size="35" />
            <br />
            Comment:
            <br />
            <textarea name="notes" rows="4" cols="40"></textarea>
            <br />
            <input type="submit" value="Submit Comment" />
            <br />
      </form>

This would be the sendmail.php file
<?php


$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];


if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Click the \"Back\" button and try again - E-mail was entered in an invalid format!</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
die ("Go back! ! ");
}

if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Click the \"Back\" button and try again - Fill in all fields!</h2>\n";
die ("Use back! ! ");
}

date_default_timezone_set("America/Chicago");
$todayis = date("l, F j, Y, g:i a");

$attn = $attn;
$subject = $attn;

$notes = stripcslashes($notes);

$message = "$todayis [CST] \n\n\n
$notes \n
From: $visitor ($visitormail)\n";

$from = "From: $visitormail\r\n";


mail("youremailaddress@email.com", $subject, $message, $from);

//to post the comments you will have to update a database like this

$sql = mysql_query("INSERT  id, subject, message, from  Values (NULL, $subject, $message, $from);");
?>


//Then simply get those values from your database and display them below the form to fill out to post a comment


Let me know if you need clarification on any of this,

Levi
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now