Go Back   Novahq.net Forum > Computers > Web design and Programming
FAQ Community Calendar Today's Posts Search

Web design and Programming Discuss website creation and other programming topics.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-13-2005, 06:21 PM
JonM is offline JonM
Registered User

Join Date: Jun 2004
Posts: 2,156

PHP Error ... Please Help, it's dealing with classes

PHP Code:
<?php
include("http://wghq.net/config.php");
class 
Comment {
    var 
$mysql_table;
    var 
$nick;
    var 
$post;
    var 
$date;
    var 
$id;
    var 
$date;
    var 
$time;
function 
add_Comment(){
    
$table trim($this->mysql_table);
    
$nick trim($this->nick);
    
$post trim($this->post);
    
$date date("m/d/Y"); 
    
$time date("h:i:s A");
    
    if(!
$post || $post==""){
        return 
false;
    }else{
        
$nick addslashes($nick);
        
$post addslashes($post);
        
$add "INSERT INTO ".$table." VALUES('null','$id','$nick','$post','$date','$time')";
        
$fin_add mysql_query($add);
        echo
'Added';
        return 
true;
    }
}
function 
read_Comments(){
    
$table trim($this->mysql_table);
    
$comments="SELECT * FROM ".$table." WHERE id='$id'";
    
$display_comments mysql_query($comments);
    while(
$comments mysql_fetch_array($display_comments)){
        
$nickname_ $comments['nick'];
        
$date_ $comments['date'];
        
$post_ $comments['post'];
        
$time_ $comments['time'];
        echo
'   <table border="0" cellpadding="4" cellspacing="0" style="border-collapse: collapse; font-size:10px; font-family:Arial" bordercolor="#111111" width="100%" id="AutoNumber2">
      <tr>
        <td width="100%">
        <table border="1" style="border-collapse: collapse; font-size: 10px; font-family: Arial" bordercolor="#800000" width="100%" id="AutoNumber3">
          <tr>
            <td width="100%">Posted By:'
.$nickname_.' :: Posted on '.$date_.', at '.$time_.'</td>
          </tr>
          <tr>
            <td width="100%">'
.$post_.'</td>
          </tr>
        </table>
        </td>
      </tr>
    </table>
        '
;
    

}
}
?>
PHP Code:
<?php
include("main_inc/comments.inc.php");
if(
$post != "yes"){
    
$comment_class = new Comment;
    
$comment_class->mysql_table "newscomments";
    
$comment_class->id $_GET['id'];
    
$read_comment $comment_class->read_Comments();
}else{
    if(
$_POST['submit']){
    
$comment_class = new Comment;
    
$comment_class->mysql_table "newscomments";
    
$comment_class->nick $_POST['nick'];
    
$comment_class->date date("m/d/Y");
    
$comment_class->time date("h:i:s A");
    
$comment_class->id $_GET['id'];
    
$comment_class->post $_POST['post'];
    
$add_comment $comment_class->add_Comment();
    if(!
$add_comment){
        echo
'Cannot add your comment, please try again!';
    }else{
        echo
'Thank you for posting your comment...please refresh this page by clicking <a href="comments.php?pg='.$_GET['$pg'].'&id='.$id.'">here</a>';
    }
}else{
    echo
'  <form method="POST" action="comments.php?pg='.$_GET['pg'].'&id='.$_GET['id'].'&post=yes">
    <table border="0" cellpadding="4" cellspacing="0" style="border-collapse: collapse; font-size:10px; font-family:Arial" bordercolor="#111111" width="100%" id="AutoNumber2">
      <tr>
        <td width="100%">
        <table border="1" cellspacing="0" style="border-collapse: collapse; font-size: 10px; font-family: Arial; color: #800000; border-style: solid; border-width: 1" bordercolor="#800000" width="100%" id="AutoNumber3" height="22">
          <tr>
            <td width="50%" height="13">Nick Name:</td>
            <td width="50%" height="13">
            <input type="text" name="nick" size="122" style="font-size: 10px; font-family: Arial; color: #800000; border-style: solid; border-width: 1"></td>
          </tr>
          <tr>
            <td width="50%" height="8">Comment:</td>
            <td width="50%" height="8">
            <textarea rows="12" name="post" cols="59" style="color: #800000; border-style: solid; border-width: 1"></textarea></td>
          </tr>
          <tr>
            <td width="50%" height="8">Submit:</td>
            <td width="50%" height="8">
            <p align="center">
            <input type="submit" value="Submit" name="submit" style="font-size: 10px; font-family: Arial; color: #800000; border-style: solid; border-width: 1"></td>
          </tr>
        </table>
        </td>
      </tr>
    </table>
    </form>
    '
;
}
}
?>
Click here to see the error: http://wghq.net/comments.php?id=1&pg=news&post=yes
Reply With Quote
  #2  
Old 05-13-2005, 07:04 PM
JonM is offline JonM
Registered User

Join Date: Jun 2004
Posts: 2,156

also you have to post to see the error
Reply With Quote
  #3  
Old 05-13-2005, 07:51 PM
Scott is offline Scott
Scott's Avatar
AKA. Panther

Join Date: Sep 2001
Location: Minneapolis, MN
Posts: 10,921

I don't understand why your using a class to do that, but whatever floats your boat. I am not a pro at classes, so if this is wrong then someone please correct me. I haven't written many classes, but this one should work.. I didn't test it but I did create a mysql table to see if it connected, and it did so it should work.

comments.inc.php
PHP Code:
 <?php 

include("http://wghq.net/config.php"); 

class 
Comment 
    var 
$table
    var 
$nick
    var 
$post
    var 
$date
    var 
$id
    var 
$date
    var 
$time
     
    function 
table($table) { 
        
$this->table=trim(addslashes($table)); 
    } 
     
    function 
submit_data($data) { 
        
$this->nick=addslashes($data['nick']); 
        
$this->date=$data['date']; 
        
$this->time=$data['time']; 
        
$this->id=$data['id']; 
        
$this->post=addslashes($data['post']); 
    } 
     
    function 
add_Comment(){ 
        if(!
$this->post){ 
            return 
false
        }else{ 
            If(!
mysql_query("INSERT INTO ".$this->table." VALUES('null','".$this->id."','".$this->nick."','".$this->post."','".$this->date."','".$this->time."'")) { 
                return 
false
            } 
            echo
'Added'
            return 
true
        } 
    } 



function 
read_Comments($id){
    
$display_comments mysql_query("SELECT * FROM ".$this->table." WHERE id='".intval($id)."'"); 
    while(
$comments mysql_fetch_array($display_comments)){ 
        
$nickname_ $comments['nick']; 
        
$date_ $comments['date']; 
        
$post_ $comments['post']; 
        
$time_ $comments['time']; 
        echo
'   <table border="0" cellpadding="4" cellspacing="0" style="border-collapse: collapse; font-size:10px; font-family:Arial" bordercolor="#111111" width="100%" id="AutoNumber2"> 
      <tr> 
        <td width="100%"> 
        <table border="1" style="border-collapse: collapse; font-size: 10px; font-family: Arial" bordercolor="#800000" width="100%" id="AutoNumber3"> 
          <tr> 
            <td width="100%">Posted By:'
.$nickname_.' :: Posted on '.$date_.', at '.$time_.'</td> 
          </tr> 
          <tr> 
            <td width="100%">'
.$post_.'</td> 
          </tr> 
        </table> 
        </td> 
      </tr> 
    </table> 
        '

      



?>
comments.php
PHP Code:
<?php 
include("main_inc/comments.inc.php"); 
if(
$post != "yes"){ 
    
$comment_class = new Comment
    
$comment_class->table("newscomments"); 
    
$read_comment=$comment_class->read_Comments($id); 
     
    print(
$read_comment); 
     
     
     
     
}else{ 
    if(
$_POST['submit']){ 
    
$comment_class = new Comment;
    
$comment_class->table("newscomments");
    
$submit_data=array( 
        
'table' => "newscomments"
        
'nick' => $_POST['nick'], 
        
'date' => date("m/d/Y"), 
        
'time' => date("h:i:s A"), 
        
'id' => $_GET['id'], 
        
'post' => $_POST['post'
    ); 
    
$comment_class->submit_data($submit_data); 
    
    if(!
$comment_class->add_Comment()){ 
        echo
'Cannot add your comment, please try again!'
    }else{ 
        echo
'Thank you for posting your comment...please refresh this page by clicking <a href="comments.php?pg='.$_GET['$pg'].'&id='.$id.'">here</a>'
    } 
}else{ 
    echo
'  <form method="POST" action="comment.php?pg='.$_GET['pg'].'&id='.$_GET['id'].'&post=yes"> 
    <table border="0" cellpadding="4" cellspacing="0" style="border-collapse: collapse; font-size:10px; font-family:Arial" bordercolor="#111111" width="100%" id="AutoNumber2"> 
      <tr> 
        <td width="100%"> 
        <table border="1" cellspacing="0" style="border-collapse: collapse; font-size: 10px; font-family: Arial; color: #800000; border-style: solid; border-width: 1" bordercolor="#800000" width="100%" id="AutoNumber3" height="22"> 
          <tr> 
            <td width="50%" height="13">Nick Name:</td> 
            <td width="50%" height="13"> 
            <input type="text" name="nick" size="122" style="font-size: 10px; font-family: Arial; color: #800000; border-style: solid; border-width: 1"></td> 
          </tr> 
          <tr> 
            <td width="50%" height="8">Comment:</td> 
            <td width="50%" height="8"> 
            <textarea rows="12" name="post" cols="59" style="color: #800000; border-style: solid; border-width: 1"></textarea></td> 
          </tr> 
          <tr> 
            <td width="50%" height="8">Submit:</td> 
            <td width="50%" height="8"> 
            <p align="center"> 
            <input type="submit" value="Submit" name="submit" style="font-size: 10px; font-family: Arial; color: #800000; border-style: solid; border-width: 1"></td> 
          </tr> 
        </table> 
        </td> 
      </tr> 
    </table> 
    </form> 
    '



?>
__________________

04' Dodge SRT-4, Mopar Stage 3, 406whp/436wtq

Last edited by Scott; 05-13-2005 at 08:22 PM.
Reply With Quote
Reply


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

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classes? atholon General Chat 16 08-21-2008 04:25 PM
Google's secret of success? Dealing with failure DevilDog#1 Hardware and Software 1 03-03-2005 10:25 AM
PHP error ... please help JonM Web design and Programming 3 01-01-2005 05:14 PM
New Character classes unknown-grunt Delta Force 6 02-28-2004 11:39 PM


All times are GMT -5. The time now is 10:02 PM.




Powered by vBulletin®