Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 727 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

How to create a comment form in PHP?

Thread title: How to create a comment form in PHP?
Closed Thread    
    Thread tools Search this thread Display Modes  
10-13-2008, 12:02 PM
#1
shilpamg is offline shilpamg
Status: Member
Join date: Aug 2008
Location:
Expertise:
Software:
 
Posts: 101
iTrader: 0 / 0%
 

shilpamg is on a distinguished road

  Old  How to create a comment form in PHP?

Please anybody tell me the code in php to create a comment form.

10-21-2008, 05:24 AM
#2
iTony is offline iTony
iTony's Avatar
Status: I'm new around here
Join date: Aug 2008
Location:
Expertise:
Software:
 
Posts: 3
iTrader: 0 / 0%
 

iTony is on a distinguished road

  Old

this is a very simple, not very secure way to do it. this is made considering you want it to save the comment in a database.

PHP Code:
<?php
if(isset($_POST['submit'])){
    if(isset(
$_POST['comment'])){
        
$comment=$_POST['comment'];
        
$connect=mysql_connect($server$username$password);
        if(!
$connect)
            echo 
"<p>failure at connecting to database server</p>";
        if(!
mysql_select_db($db$connect))
            echo 
"<p>failure at selecting db</p>";
        
mysql_query("INSERT INTO tbl_comments(comment_text) VALUES(".$comment.")");
        echo 
"<p>Comment added to database.</p>";
    }else{
        echo 
"<p>No text was submitted.</p>";
    }
}else{
?>
<form method="post" action="<?php $_SERVER['PHP_SELF'?>">
    <label for="comment">Give your comment</label><br />
    <textarea name="comment" id="comment"></textarea><br />
    <input type="Submit" name="submit" id="submit" value="submit" />
</form>
<?php }
?>
There is many examples in the internet about this though. it's a everyday task for a website.

10-22-2008, 12:04 PM
#3
shilpamg is offline shilpamg
Status: Member
Join date: Aug 2008
Location:
Expertise:
Software:
 
Posts: 101
iTrader: 0 / 0%
 

shilpamg is on a distinguished road

  Old

Thanks to help me.

I want to use the name, mail-id, website url and comment in the comment form then how will i do?

11-27-2008, 01:01 AM
#4
coder-chris is offline coder-chris
Status: I'm new around here
Join date: Nov 2008
Location:
Expertise:
Software:
 
Posts: 12
iTrader: 0 / 0%
 

coder-chris is on a distinguished road

  Old

Hi. You would need to have some extra text fields in the HTML.

Give them different names.

Then refer to them in the PHP as using the post array: $_POST['fieldname'].

When it comes to inserting it in the database, just make different attributes for each thing you want to store: name, mail-id, url, comment and probably an auto number for ID.

11-27-2008, 10:26 AM
#5
shilpamg is offline shilpamg
Status: Member
Join date: Aug 2008
Location:
Expertise:
Software:
 
Posts: 101
iTrader: 0 / 0%
 

shilpamg is on a distinguished road

  Old

Please tell me how will i use the session and cookie in this comment form?

11-29-2008, 03:39 AM
#6
jFrost is offline jFrost
Status: I'm new around here
Join date: Nov 2008
Location:
Expertise:
Software:
 
Posts: 2
iTrader: 0 / 0%
 

jFrost is on a distinguished road

  Old

Originally Posted by shilpamg View Post
Please tell me how will i use the session and cookie in this comment form?
Why do you need sessions and cookies? What information do you want to store? They are there for a reason - not just to sound good.

If you simply want to show the information they submitted on the page, a simple "echo" would do. So what exactly do you want to store in the sessions and cookies?

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed