koolkat67 Posted March 26, 2007 Share Posted March 26, 2007 I set up a comment page on my site and most users can enter comments. the page refreshes and shows the comments below. however, some users can't enter comments. what should I be looking for to resolve this? Quote Link to comment Share on other sites More sharing options...
Leeder Posted March 26, 2007 Share Posted March 26, 2007 Something that sets those users apart from other users who can enter comments.. Is it the time of day, IP, area, etc? Quote Link to comment Share on other sites More sharing options...
koolkat67 Posted March 26, 2007 Author Share Posted March 26, 2007 I have no clue. i mean they're all using IE and basic Windows 2000 or XP. Dont know what is happening Quote Link to comment Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 Can we see some code? Quote Link to comment Share on other sites More sharing options...
Lumio Posted March 26, 2007 Share Posted March 26, 2007 Leeder... it's because of the warm and nice weather today Quote Link to comment Share on other sites More sharing options...
koolkat67 Posted March 26, 2007 Author Share Posted March 26, 2007 sure...im a total newbie to php so dont laugh at my coding...lol. there is probably more than i need to post there. I appreciate the help <div id="blogcommentform"> <?php if($submit) { $db = mysql_connect("mysql", "*", "*"); mysql_select_db("akbhangu"); $blog="sleepyheads"; $sql = "INSERT INTO mainblogcomments (name, location, comment, blog) VALUES ('$name', '$location', '$comment', '$blog')"; $result = mysql_query($sql); $sql = "ALTER TABLE mainblogcomments ORDER BY `id` DESC"; $result = mysql_query($sql); echo "Thank you! Information entered.\n"; mysql_close(); header("Location: /mainblogcomments.php"); } ?> <FORM ACTION="<?php echo $PHP_SELF; ?>" METHOD=POST> <table> <tr><td align="right">First name:</td><td align="left"><input type="Text" name="name" width="200"></td></tr> <tr><td align="right">Location:</td><td align="left"><input type="Text" name="location" width="200"></td></tr> <tr><td colspan="2">Comments (Remember:Family site so keep it clean):</td></tr> <tr><td colspan="2"><TEXTAREA NAME="comment" ROWS=5 COLS=40></TEXTAREA></td></tr> <tr><td align="center" colspan="2"><input type="Submit"name="submit" value=" Enter information"></td></tr></table> </form> </div> <hr /> <div id="blogcomments"> <?php $db = mysql_connect("mysql", "*", "*"); mysql_select_db("akbhangu"); $result = mysql_query("SELECT * FROM mainblogcomments WHERE blog='sleepyheads'"); ?> <table> <tr align="center"><td width="500">Comment</td><td width="200">Last Post</td></tr> <?php $i=0; while($myrow = mysql_fetch_array($result)) { $i++; if ($i % 2 ==0) { ?> <tr align="left" valign="top"> <td><?php echo $myrow["comment"];?></td> <td>| by <?php echo $myrow["name"];?> in <?php echo $myrow["location"];?><br />| on <?php echo $myrow["date"];?></td> </tr> <?php } else {?> <tr align="left" valign="top"> <td bgcolor="#FFFFCC"><?php echo $myrow["comment"];?></td> <td bgcolor="#FFFFCC">| by <?php echo $myrow["name"];?> in <?php echo $myrow["location"];?><br />| on <?php echo $myrow["date"];?></td> </tr> <?php } } ?> </table> </div> Quote Link to comment Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 It looks better when you use the [ code ] [ /code ] tags. Quote Link to comment Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 $sql = "INSERT INTO mainblogcomments (name, location, comment, blog) VALUES ('$name', '$location', '$comment', '$blog')"; $result = mysql_query($sql); $sql = "ALTER TABLE mainblogcomments ORDER BY `id` DESC"; I take it id is an auto_increment value? If so this should work with no problems unless name is UNIQUE if so that is where the problem lies. Also I do not know why you would want to use the alter table right there when you can specify the order by when retrieving data. I would think the alter by every time would cause a major slowdown if the table contained a lot of data. Quote Link to comment Share on other sites More sharing options...
koolkat67 Posted March 26, 2007 Author Share Posted March 26, 2007 id is auto_inc and nothing is unique. the alter table I can fix later...there are only 4 entries so far. but what could cause some users to not be able to enter comments? Quote Link to comment Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 <?php if(isset($_POST['submit'])) calling it by $submit is very bad and means register_globals is on which is a potential security breach. Replace the $submit with the above code and see what happens. Quote Link to comment Share on other sites More sharing options...
koolkat67 Posted March 26, 2007 Author Share Posted March 26, 2007 ok i changed it and I'll have to see if they can add comments again. my register_globals is on though. would this stop some users from entering comments tho? Quote Link to comment Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 It may depending on how the browser sends the data to the script. Quote Link to comment Share on other sites More sharing options...
koolkat67 Posted March 26, 2007 Author Share Posted March 26, 2007 yeah but we're using the same browsers and platforms. got any other ideas? I haven't heard back from my friends yet. thats the other goofy thing about this is I can't even test it until they test it for me...lol Quote Link to comment Share on other sites More sharing options...
koolkat67 Posted March 27, 2007 Author Share Posted March 27, 2007 actually i just found out that one of the users is using IE7. anyone seen issues with this? Quote Link to comment Share on other sites More sharing options...
yzerman Posted March 27, 2007 Share Posted March 27, 2007 php coding should be browser independant. You also have no commenting showing anyone else what you are doing, this is a bad thing especially when your looking for support. I have changed the code as follows: Removed the header comment, this is not needed as the user is redirected to the page after he submits. Added error checking. My guess is that one or all of the fields in the database are set to not accept null values, so I check to see if the values are null before submitting to the db. changed the date format - I store the date in unix format - I didnt see where you had that in your code - so I added $date = time(), and stored to the database in the date field. Hope this helps. you can view the code in action at http://www.sandynpaul.com/test/addcomment.php <div id="blogcommentform"> <?php //connect to the database $db = mysql_connect("localhost", "*", "*"); mysql_select_db("*"); if(isset($_POST['submit'])) { //if the user has submitted the form //Should have some checking variable checking going on here so that the variables are defined regardless of the users input; if (isset($_POST['name'])) { $name = $_POST['name']; } else { $name = NULL; } if (isset($_POST['location'])) { $location = $_POST['location']; } else { $location = NULL; } if (isset($_POST['comment'])) { $comment = $_POST['comment']; } else { $comment = NULL; } $blog="sleepyheads"; $date = time(); if ($name && $location && $comment) { //if the variables are set $sql = "INSERT INTO mainblogcomments (name, location, comment, blog, date) VALUES ('$name', '$location', '$comment', '$blog', '$date');"; $result = mysql_query($sql); $sql = "ALTER TABLE mainblogcomments ORDER BY `id` DESC"; $result = mysql_query($sql); echo "Thank you! Information entered.\n"; mysql_close(); } else { //variables arent set, lets echo an error message for the ones not set if ($name == NULL) { echo 'You must enter a name!'; } if ($comment == NULL) { echo 'You must enter a comment!'; } if ($location == NULL) { echo 'You must enter a location!'; } } } ?> <FORM ACTION="<?php echo $PHP_SELF; ?>" METHOD=POST> <table> <tr><td align="right">First name:</td><td align="left"><input type="Text" name="name" width="200"></td></tr> <tr><td align="right">Location:</td><td align="left"><input type="Text" name="location" width="200"></td></tr> <tr><td colspan="2">Comments (Remember:Family site so keep it clean):</td></tr> <tr><td colspan="2"><TEXTAREA NAME="comment" ROWS=5 COLS=40></TEXTAREA></td></tr> <tr><td align="center" colspan="2"><input type="Submit" name="submit" value=" Enter information"></td></tr></table> </form> </div> <div id="blogcomments"> <?php //connect to the database $db = mysql_connect("localhost", "*", "*"); mysql_select_db("*"); $result = mysql_query("SELECT * FROM mainblogcomments WHERE blog='sleepyheads'"); ?> <table> <tr align="center"><td width="500">Comment</td><td width="200">Last Post</td></tr> <?php $i=0; while($myrow = mysql_fetch_array($result)) { $i++; if ($i % 2 ==0) { ?> <tr align="left" valign="top"> <td><?php echo $myrow["comment"];?></td> <td>| by <?php echo $myrow["name"];?> in <?php echo $myrow["location"];?> | on <?php echo date("Y-m-d H:i:s",$myrow["date"]);?></td> </tr> <?php } else {?> <tr align="left" valign="top"> <td bgcolor="#FFFFCC"><?php echo $myrow["comment"];?></td> <td bgcolor="#FFFFCC">| by <?php echo $myrow["name"];?> in <?php echo $myrow["location"];?> | on <?php echo date("Y-m-d H:i:s", $myrow["date"]);?></td> </tr> <?php } } ?> </table> </div> Quote Link to comment Share on other sites More sharing options...
koolkat67 Posted March 27, 2007 Author Share Posted March 27, 2007 ah man, i totally have to beef up my commenting, i know! thanks so much for putting all this effort into this. www.alaskabhangu.com is my site by the way and if you click on Have a Comment it goes to this page. I'll try your code tonight but even if you miss entering in a field it still goes to my db and leaves the unentered fields empty. Quote Link to comment Share on other sites More sharing options...
koolkat67 Posted March 28, 2007 Author Share Posted March 28, 2007 well i just discovered something it is totally the IE7 thing. Now does anyone have a solution. We installed IE 7 and got this problem. However if we TAB to the button and hit ENTER it works but you can't mouse click on the button. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 28, 2007 Share Posted March 28, 2007 Sometimes using isset($_POST['submit']) can be dangerous. Some browsers (I'm not sure which off hand) will not send the submit variable if the submit button is not pressed. This means if the user simply types in the form, then presses the "Enter" key, the submit button's value is not sent, which means that the $_POST array key "submit" will not exist. Quote Link to comment Share on other sites More sharing options...
koolkat67 Posted March 28, 2007 Author Share Posted March 28, 2007 so what should I be using to make it work? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.