twilitegxa Posted June 29, 2010 Share Posted June 29, 2010 I have this php chat room I found online, and I was trying to make a few additions, but I am running into some trouble. When the user clicks a smiley face button, I want the smiley face icon image to display in the chat instead of just the text, like shows up now, but i want the image to show up. Can anyone help me with that? Also I am receiving this error when a chat message finally shows up in the chat: Notice: Undefined variable: message in C:\wamp\www\chatlog.php on line 35 Here is the main page that shows the chat: chatframe: <?php print "<iframe src='chatlog.php' name='chatlogframe' width='350' height='400'></iframe>"; print "<br><br>"; print "<iframe src='submit.php' width='380' height='180' frameborder='0'scrolling='no'></iframe><br><br>"; ?> Here is the submit page: submit.php: <?php include "connect.php"; if(isset($_POST['submit'])) //if submit button push has been detected { $message=$_POST['message']; $name=$_POST['name']; if(strlen($message)<1) { print "You did not input a message"; } else if(strlen($name)<1) { print "You did not enter a name, please try again."; } else { $message=strip_tags($message); $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP $checkforbanned="SELECT ip from ipbans where ip='$IP'"; $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS"); if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list { print "You IP is banned from posting."; } else { $thedate = date("U"); //grab date and time of the post $insertmessage="INSERT into chatmessages (name,ip,postime,message) values('$name','$IP','$thedate','$message')"; mysql_query($insertmessage) or die("Could not insert message"); } } } print "<form action='submit.php' method='post' name='form'>"; print "Your name:<br>"; print "<input type='text' name='name' size='20'><br>"; print "Your message:<br>"; print "<textarea name='message' cols='40' rows='2'></textarea><br>"; print "<a onClick=\"addSmiley('')\"><img src='images/smile.gif'></a> "; //replace images/smile.gif with the relative path of your smiley print "<a onClick=\"addSmiley('')\"><img src='images/sad.gif'></a> "; print "<a onClick=\"addSmiley('')\"><img src='images/wink.gif'></a> "; print "<input type='submit' name='submit' value='submit'></form>"; print "<script language=\"Java Script\" type=\"text/javascript\">\n"; print "function addSmiley(textToAdd)\n"; print "{\n"; print "document.form.message.value += textToAdd;"; print "document.form.message.focus();\n"; print "}\n"; print "</script>\n"; print "<br><br>"; ?> And here is the chatlog page: chatlog.php: <?php include "connect.php"; $getnummessages="SELECT COUNT(*) as messagecount from chatmessages"; $getnummessages2=mysql_query($getnummessages) or die("blah"); $getnummessages3= mysql_result($getnummessages2, 0); if($getnummessages3>21) { $startrow=$getmessages3-20; } else { $startrow=1; } $getmsg="SELECT name, message from chatmessages order by postime ASC limit $startrow,$getnummessages3"; $getmsg2=mysql_query($getmsg) or die(mysql_error()); while($getmsg3=mysql_fetch_array($getmsg2)) { $message=Smiley($message); //Smiley faces print "<font color='red'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; } function Smiley($texttoreplace) { $smilies=array( '' => "<img src='images/smile.gif'>", ':blush' =>"<img src='images/blush.gif'>", ':angry' =>"<img src='images/angry.gif'>", ''=> "<img src='images/shocked.gif'>", 'fuck'=>"$#$%", 'Fuck'=>"&$#@" ); $texttoreplace=str_replace(array_keys($smilies), array_values($smilies), $texttoreplace); return $texttoreplace; } ?> <script> setTimeout("window.location.replace('chatlog.php')",2000); </script> I see it's using a function to display the smileys, but I can't figure out how to make them the images instead of the text. Can anyone help? 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.