Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

895 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

13 Experts available now in Live!

Get 1:1 Help Now