Solved

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

Posted on 2008-10-17
3
204 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why is my wamp get_include_path() wrong? 2 21
Accessing specific element - DOM PHP HTML 8 37
Log in through ID 5 19
What is this? I've never seen this... 2 9
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

820 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