Jump to content

PHP Comment System


herghost

Recommended Posts

Good Afternoon everyone.

 

I am having some problems in getting a script I found on a forum to work, I have tried contacting the original author but with no joy.

 

Basically its a php/ajax comment system, however I am getting these errors

 

Notice: Undefined index: type in C:\wamp\www\buy2earn\viewm.php on line 93

Notice: Undefined index: type in C:\wamp\www\buy2earn\viewm.php on line 105

 

Here is the portion of code that I am working on, I don't understand what $_post['type'] is meant to come from? I guess its basically if the form has been submitted, but if I change the values tp 'submit' I still get the same result, just with the message submit is undefined instead!

 

 

<?php 
$date=date("Y-m-d"); 
$username = $_SESSION['username'];

if($_POST['type'] == "addcomment") {
    $username = mysql_real_escape_string($_POST['username']);
    $comment = mysql_real_escape_string($_POST['comment']);
    
    if($username == "" || $comment == "") { 
        die("<p><font color='red'>Error: Please include a message.</font></p>"); 
    }
    $q1 = mysql_query("INSERT INTO 'comments' ('c_id', 'm_id', 'username', 'date', 'comment')
VALUES ('', '$m_id', '$username', '$date', '$comment')")
 or die("<p>Mysql Error: <b>".mysql_error()."</b></p>");

    echo "<p><font color='green'>Comment added successfully.</font></p>";
} elseif($_POST['type'] == "getcomments") { 
    $q1 = mysql_query("SELECT * FROM 'comments'");
    $n1 = mysql_num_rows($q1);
    if($n1 == 0) { 
        die("<p><font color='red'>No comments were found.</font></p>");
    }
    echo "<table border=1>";
    echo "<tr><td><b>User</b></td><td><b>Comment</b></td></tr>";
    while($r1 = mysql_fetch_assoc($q1)) { 
        $a = $r1['username'];
        $m = $r1['comment'];
        echo "<tr><td>$a</td><td>$m</td></tr>";
    }
    echo "</table>";
} else {?>
    <div style="font-size: 18px;">
        <p>Current Comments: </p>
        <div id="comments"></div> 
        <hr />
        <p>Add a comment:</p>
        <form action="<?php $_SERVER['PHP_SELF'];?>" method="post">
            <p>Username: <input type="text" name="username" id="username" /></p>
            <p>Comment: <textarea name="message" cols="50" rows="10" id="message"></textarea></p>
            <p><input type="submit" name="submit" value="Add Comment" id="submit" /></p>
        </form>
        <div id="return"></div> 
    </div>
    

<?php } ?>
    

 

Many Thanks for any help

 

Link to comment
Share on other sites

it's a notice not an error. its just bringing your attention to a possible problem.

the code works as it should.

but BlueSky is on the right track to fix it.

 

easiest solution is to define the post if it doesn't exist.

if(!isset($_POST['type'])) $_POST['type']=NULL;

at the top should do the trick.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.