Solved

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

Posted on 2008-10-17
3
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to implement server side field validation and display customized error messages to the client.
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 dynamically set the form action using jQuery.

732 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