Solved

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

Posted on 2008-10-17
3
202 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
ID: 22742849
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
ID: 22742997
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

770 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