twilitegxa Posted September 11, 2009 Share Posted September 11, 2009 How can I alter my chat script to show the selected character's name in the message window instead of the username? I have the following pages: chatframe.php: <?php session_start(); if(!isset($_SESSION['loggedIn'])) { header("Location: login.php"); } ?> <html> <head> <title>Sailor Moon RPG - Battle Chat</title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <!-- HEADER --> <h1 class="logo">Sailor Moon RPG</h1> <!-- /HEADER --> <?php include("topnav.php"); ?> <div id="main"> <?php include("includes/log.php"); ?> <?php include("mainnav.php"); ?> <h1>Sailor Moon RPG - Battle Chat</h1> <?php print "<table width=80%><tr><td><iframe src='chatlog.php' name='chatlogframe' width='80%' height='400'></iframe></td></tr>"; print "<tr><td><iframe src='submit.php' width='80%' height='250' frameborder='0' class='message'></iframe></td></tr></table>"; ?> </div> <?php include("bottomnav.php"); ?><!-- FOOTER --> <!-- FOOTER --> <div id="footer_wrapper"> <div id="footer"> <p>Sailor Moon and all characters are<br /> trademarks of Naoko Takeuchi.</p> <p>Copyright © 2009 Liz Kula. All rights reserved.<br /> A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p> <div id="foot-nav"> <ul> <li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li> <li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li> </ul> </div> </div> </div> <!-- /FOOTER --> </body> </html> chatlog.php <?php session_start(); ?> <html> <head> <title></title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <?php include "connect.php"; $getnummessages="SELECT COUNT(*) as messagecount from chatmessages"; $getnummessages2=mysql_query($getnummessages) or die(mysql_error()); $getnummessages3= mysql_result($getnummessages2, 0); if($getnummessages3>10000000) { $startrow=$getmessages3-20; } else { $startrow=0; } $getmsg="SELECT name, message from chatmessages order by postime DESC limit $startrow,$getnummessages3"; $getmsg2=mysql_query($getmsg) or die(mysql_error()); while($getmsg3=mysql_fetch_array($getmsg2)) { $message=' '; $message=Smiley($message); //Smiley faces $getmsg3['message'] = nl2br($getmsg3['message']); //includes line breaks in messages $getmsg3['message'] = wordwrap($getmsg3['message'],170,'<br />',true); print "<font color='teal'><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')",1000); </script> </body> </html> submit.php: <?php session_start(); ?> <html> <head> <title></title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <?php include "connect.php"; if(isset($_POST['submit'])) //if submit button push has been detected { $message= nl2br($_POST['message']); $name=$_SESSION['userName']; if(strlen($message)<1) { print "You did not input a message"; } else if(strlen($name)<1) { print "You are not logged in. Please log in."; } 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 "Your IP is banned from posting. Please contact administration."; } 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 "<strong>Your name:</strong><br>"; not needed //print "<input type='text' name='name' size='20'><br>"; not needed print "<strong>Your message:</strong><br>"; print "<textarea name='message' cols='40' rows='4'></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>"; ?> </body> </html> I know I need to use this statement to get the identity of the character to display it, bu I don't know how to replace the username in the chat window with the character's identity: include "connect_db.php"; $get_identity = "select id, identity from scouts where id = '$_GET[id]'"; $get_identity_res = mysql_query($get_identity, $conn) or die(mysql_error()); while ($get_scouts = mysql_fetch_array($get_identity_res)) { $id = $get_scouts['id']; $identity = $get_scouts['identity']; } How can I do this? What page do I need to put the code on in order for it to display properly? I have this page where they choose their character and it points the user to the chatframe.php with the selected character id: choose_character.php: <?php session_start(); if(!isset($_SESSION['loggedIn'])) { header("Location: login.php"); } ?> <?php include("connect_db.php"); ?> <html> <head> <title>Choose Character</title> <style type="text/css" media="screen"> /*<![CDATA[*/ @import url(global.css); /*]]>*/ </style> </head> <body> <!-- HEADER --> <h1 class="logo">Sailor Moon RPG</h1> <!-- /HEADER --> <?php include("topnav.php"); ?> <div id="main"> <?php include("includes/log.php"); ?> <?php include("mainnav.php"); ?> <h3>Which character would you like to play?</h3> <?php echo "<table><tr><td valign=top>"; //verify Scouts exist in category and list if applicable $verify_category = "select id, identity, username from scouts where username = '".$_SESSION['userName']."'"; $verify_category_res = mysql_query($verify_category, $conn) or die(mysql_error()); if (mysql_num_rows($verify_category_res) < 1) { echo "<i>You have no Scouts created.</i> <a href=creationform.php>Create one</a>?<br>"; } else { echo "<b>Scouts:</b>"; while ($list_scouts = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_scouts['identity']); $scout_id = $list_scouts['id']; echo "<ul class=choose> <li><a href=chatframe.php?id=$scout_id>$identity</a></li> </ul>"; } } echo "<br>"; //verify Knights exist in category and list if applicable $verify_category = "select id, identity, username from knights where username = '".$_SESSION['userName']."'"; $verify_category_res = mysql_query($verify_category, $conn) or die(mysql_error()); if (mysql_num_rows($verify_category_res) < 1) { echo "<i>You have no Knights created.</i> <a href=creationform.php>Create one</a>?<br>"; } else { echo "<b>Knights:</b>"; while ($list_knights = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_knights['identity']); $scout_id = $list_knights['id']; echo "<ul class=choose> <li>$identity</li> </ul>"; } } echo "<br>"; //verify Female Dark Warriors exist in category and list if applicable $verify_category = "select id, identity, username from fdark_warrior where username = '".$_SESSION['userName']."'"; $verify_category_res = mysql_query($verify_category, $conn) or die(mysql_error()); if (mysql_num_rows($verify_category_res) < 1) { echo "<i>You have no Female Dark Warriors created.</i> <a href=creationform.php>Create one</a>?<br>"; } else { echo "<b>Female Dark Warriors:</b>"; while ($list_fdark_warriors = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_fdark_warriors['identity']); $scout_id = $list_fdark_warriors['id']; echo "<ul class=choose> <li>$identity</li> </ul>"; } } echo "<br>"; //verify Male Dark Warriors exist in category and list if applicable $verify_category = "select id, identity, username from mdark_warrior where username = '".$_SESSION['userName']."'"; $verify_category_res = mysql_query($verify_category, $conn) or die(mysql_error()); if (mysql_num_rows($verify_category_res) < 1) { echo "<i>You have no Male Dark Warriors created.</i> <a href=creationform.php>Create one</a>?<br>"; } else { echo "<b>Male Dark Warriors:</b>"; while ($list_mdark_warriors = mysql_fetch_array($verify_category_res)) { $identity = ucwords($list_mdark_warriors['identity']); $scout_id = $list_mdark_warriors['id']; echo "<ul class=choose> <li>$identity</li> </ul>"; } } echo "</td>"; $get_stats = "select * from stats where identity = '$identity'"; $get_stats_res = mysql_query($get_stats, $conn) or die(mysql_error()); while ($stats_info = mysql_fetch_array($get_stats_res)) { $body = $stats_info['body']; $mind = $stats_info['mind']; $soul = $stats_info['soul']; echo "<td valign=top> <div id=chosen> <h1>$identity</h1> Body: $body<br> Mind: $mind<br> Soul: $soul<br><br>"; //gather derived values $get_derived = "select * from derived_values where identity = '$identity'"; $get_derived_res = mysql_query($get_derived, $conn) or die(mysql_error()); while ($derived_info = mysql_fetch_array($get_derived_res)) { $health = $derived_info['health']; $energy = $derived_info['energy']; $acv1 = $derived_info['acv1']; $acv2 = $derived_info['acv2'] . ' (for Sailor Scout Attack)'; $dcv1 = $derived_info['dcv1']; $dcv2 = $derived_info['dcv2'] . ' (for Sailor Scout Attack)'; $total_cp = $derived_info['total_cp']; if($health == 0 || $health == '0' || $health == null){$GLOBALS['health'] = "";} if($energy == 0 || $energy== '0' || $energy == null){$GLOBALS['energy'] = "";} if($acv1 == 0 || $acv1 == '0' || $acv1 == null){$GLOBALS['acv1'] = "";} if($acv2 == 0 || $acv2 == '0' || $acv2 == null){$GLOBALS['acv2'] = "";} if($dcv1 == 0 || $dcv1 == '0' || $dcv1 == null){$GLOBALS['dcv1'] = "";} if($dcv2 == 0 || $dcv2 == '0' || $dcv2 == null){$GLOBALS['dcv2'] = "";} if($total_cp == 0 || $total_cp == '0' || $total_cp== null){$GLOBALS['total_cp'] = "";} echo " Health Points: $health<br> Energy Points: $energy<br> Attack Combat Value: $acv1 $acv2<br> Defense Combat Value: $dcv1 $dcv2<br>"; } } echo "<br> <input type=button value=Choose></div></td></tr></table>"; ?> </div> <?php include("bottomnav.php"); ?> <!-- FOOTER --> <div id="footer_wrapper"> <div id="footer"> <p>Sailor Moon and all characters are<br> trademarks of Naoko Takeuchi.</p> <p>Copyright © 2009 Liz Kula. All rights reserved.<br> A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p> <div id="foot-nav"><!-- <ul> <li><a href="http://validator.w3.org/check?uri=http://webdesignsbyliz.com/digital/index.php" target="_blank"><img src="http://www.w3.org/Icons/valid-xhtml10-blue" alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li> <li><a href="http://jigsaw.w3.org/css-validator/validator?uri=http://webdesignsbyliz.com/digital/global.css" target="_blank"><img class="c2" src="http://jigsaw.w3.org/css-validator/images/vcss-blue" alt="Valid CSS!" /></a></li> </ul> --></div> </div> </div> <!-- /FOOTER --> </body> </html> </body> </html> I need to have the page that submits the message to insert the character identity instead of the userName. Link to comment https://forums.phpfreaks.com/topic/173936-displaying-character-name-in-chat-window/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.