By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,077 Members | 961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,077 IT Pros & Developers. It's quick & easy.

Where's error? Simple shoutbox code... with a few features

P: n/a
Well I've made alot of progress (ok i lie someone made alot of progress
for me) but I'm at a hault because i get the "can't write to db" error
down in the code.

What's wrong? I can't find it....

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  
  4.  
  5. $badwordlist =
  6. array("addbadwirdsere","addbadwirdsere","addbadwirdsere","addbadwirdsere");
  7.  
  8.  
  9. mysql_connect("xxxxx","xxxx","xxxxx");
  10. mysql_select_db("xxxxxx");
  11.  
  12.  
  13. if ($_POST['submit']) {
  14. putenv('TZ=America/New_York');
  15. $time = date("F j, Y, g:i a", time());
  16.  
  17.  
  18. if (substr_count($_POST['message'],'http') < 2) {
  19. $tomanylinks = true;
  20.  
  21. }
  22.  
  23.  
  24.  
  25. foreach($badwordlist as $badword) {
  26. if (strpos($_POST['message'],$badword)) {
  27. $badwordfound = true;
  28. break;
  29. }
  30. }
  31.  
  32. if (!$tomanylinks && !$badwordfound) {
  33. $result = mysql_query("
  34. INSERT INTO shoutbox (
  35. name,
  36. message,
  37. time
  38. ) VALUES (
  39. '{$_POST['name']}',
  40. '{$_POST['message']}',
  41. '$time'
  42. )");
  43. }
  44.  
  45. if ($result) {
  46. header("Location: {$_SERVER['PHP_SELF']}");
  47. } else {
  48. die("FIRST There was an error adding to the shoutbox");
  49. }
  50.  
  51. } else {
  52. echo "<form action=\"{$_SERVER['PHP_SELF']}\"
  53. method=\"post\">";
  54. echo "  <input id=\"name\" type=\"text\" name=\"name\" />";
  55. echo "  <input type=\"submit\" name=\"submit\" value=\"Submit\"
  56. />";
  57. echo "  <textarea rows=\"2\" cols=\"35\"
  58. name=\"message\"></textarea>";
  59. echo "</form>";
  60. if ($result = mysql_query("select * from shoutbox order by id
  61. desc limit 40")) {
  62. while($r = mysql_fetch_array($result)) {
  63. ?>
  64.  
  65. <div class="weblog_comment">
  66. <div class="weblog_comment_name"><?php echo $r['name'] ?></div>
  67. <div class="weblog_comment_time"><?php echo $r['time'] ?></div>
  68. <div class="weblog_comment_message"><?php echo $r['message'] ?><br
  69. /><br /></div>
  70. </div>
  71.  
  72. <?php
  73. }
  74. } else {
  75. die("SECOND There was an error displaying the shoutbox");
  76. }
  77. }
  78.  
  79. ?>
  80.  
  81.  
  82.  
Jul 29 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.