Current location: Hot Scripts Forums » Programming Languages » PHP » PHP Comments


PHP Comments

Reply
  #1 (permalink)  
Old 03-19-04, 06:27 PM
omgwtf omgwtf is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Red face PHP Comments

Hello

I'm trying to make profiles on my site comment-able. I'm pretty new to php, so please bare with me, heh.
The profiles are dynamic, so the url would be like, www.blablablabla.com/profile.php?key=2

$key is the profile ID (number)

the script almost (not really, heh) works. It doesnt insert the name and comment into the database, but it does make a new 'comment id' and saves the 'profile id'.
The other problem is, it only spits out the tables (without data) and the "back" button.

sorry if this was stupidly explained.

Anyways, here is the code:

PHP Code:

<?php

    
include ("db.php");
    function 
addcomment($key
    {
        
$query "INSERT INTO b2p_comments (comment_id, profile_id, name, COMMENT) VALUES ('', '$key', '{$_POST['name']}', '{$_POST['COMMENT']}')";
        
mysql_query($query);
        echo 
"COMMENT entered. Thanks!<BR>\n";
    }
    function 
displaycomments($key
    {
        include (
"db.php");
        
$key = @$HTTP_GET_VARS["key"];
        if (empty(
$key)) {
        
$key = @$HTTP_POST_VARS["key"];
        global 
$key;
        
$query "SELECT * FROM b2p_comments WHERE profile_id = '$key'";
        
$result mysql_query ($query);
        while(
$row mysql_fetch_object($result))
     {

        echo 
"<TABLE border=\"1\" width=\"300\">\n";
        
        
$name htmlentities ($row['name']);
        echo 
"<TR><TD><b>by: $name</b></TD></TR>\n";
    
        
$COMMENT strip_tags ($row['COMMENT'], '<a><b><i><u>');
        
$COMMENT nl2br ($COMMENT);
        echo 
"<TR><TD>$COMMENT</TD></TR>\n";    
        echo 
"</TABLE>\n";
        echo 
"<BR>\n";
        echo 
"<a href=\"{$_SERVER['PHP_SELF']}"?key=$key\">Back</a>\n";
        echo 
"<HR width=\"300\">";
        echo 
"<FORM action=\"{$_SERVER['PHP_SELF']}"?action=addCOMMENT&id=$key\" method=POST>\n";
        echo 
"Name: <input type=\"text\" " "width=\"30\" name=\"name\"><BR>\n";
        echo 
"<TEXTAREA cols=\"40\" rows=\"5\" " "name=\"COMMENT\"></TEXTAREA><BR>\n";
        echo 
"<input type=\"submit\" name=\"submit\" " "value=\"Add COMMENT\"\n";
        echo 
"</FORM>\n";

     }
       }
    }

switch(
$_GET['action']) {
    
    case 
'addcomment':
        global 
$id;
        
addcomment($_GET['$id']);
        break;
    default:
        global 
$key;
        include (
"db.php");
        
displaycomments($_GET['$key']);
;

}


?>
What am I doing terribly wrong?
Reply With Quote
  #2 (permalink)  
Old 03-19-04, 08:28 PM
Slikk Slikk is offline
New Member
 
Join Date: Mar 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Ok, it's inserting a comment id and profile id, but nothing else you say and are you recieving any type of errors message? Possibly you might want to addslashes to the actual name and comment too, so in that case if something like quotation marks are entered in the name or comment, you won't get MySQL Errors if they are displaying.

I really don't see anything wrong with the code, unless I missed something, but generally I really don't use "global $somevar", with HTTP Vars. Sometimes, I just use it as it's given, like $key, without making it global or anything, but not sure if that's the problem you are having.
Reply With Quote
  #3 (permalink)  
Old 03-20-04, 03:26 PM
omgwtf omgwtf is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
no errors at all.


(hah, never thought Id be sad over that)


anywho, thanks for your help

Anyone else have an idea?
Reply With Quote
Reply

Bookmarks


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 06:02 AM
100 Web Templates & 10 PHP Scripts for sale! HostersUK.co.uk General Advertisements 0 01-10-04 12:31 AM
Realtime PHP Code Obfuscation barrywien General Advertisements 1 11-16-03 06:50 PM
PHP Comments Script JavaHead Script Requests 0 09-21-03 07:49 AM


All times are GMT -5. The time now is 10:20 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.