herghost Posted November 14, 2010 Share Posted November 14, 2010 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 https://forums.phpfreaks.com/topic/218637-php-comment-system/ Share on other sites More sharing options...
Rifts Posted November 14, 2010 Share Posted November 14, 2010 you probably need to ass if(isset(if($_POST['type'])) Link to comment https://forums.phpfreaks.com/topic/218637-php-comment-system/#findComment-1134058 Share on other sites More sharing options...
BlueSkyIS Posted November 14, 2010 Share Posted November 14, 2010 you need to make sure $_POST['type'] exists before checking it's value. you can add the condition to your IF: if(isset($_POST['type']) && $_POST['type'] == "addcomment") { /// blah blah blah } elseif(isset($_POST['type']) && $_POST['type'] == "getcomments") { /// etc. Link to comment https://forums.phpfreaks.com/topic/218637-php-comment-system/#findComment-1134072 Share on other sites More sharing options...
laffin Posted November 14, 2010 Share Posted November 14, 2010 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 https://forums.phpfreaks.com/topic/218637-php-comment-system/#findComment-1134169 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.