Hi,
I have trouble with a chatscript. By trying out the script I get no textarea
for chatmessages. After login the loginpage will be shown again.
What can be the problem? Attached you will find the code.
Regards,
Ruprecht
<?
// Datenbank schreibe
$dhost = "localhost"; // hostname
$dbuser = "root"; // user
$dpw = ""; // paßwort
$dbname = "czchat"; // Datenbankname
$db = @mysql_connect("$dhost","$dbuser","$dpw");
mysql_select_db($dbname);
$linec = 3;
echo $doing;
if (empty($doing))
{
$doing == "-";
ShowLoginForm();
}
elseif ($doing == "posts")
ShowAddPosts();
elseif ($doing == "form")
GetInput();
elseif ($doing == "enter")
Login();
function ShowLoginForm() {
echo '<body bgcolor="#CCCCCC">';
echo "<b>Wähle deinen nickname</b>";
echo ' <form name="chat" method="get" action="cz_chat.php">';
echo ' <input type="text" name="nick" size="20">';
echo ' <input type="text" name="doing" value="enter">';
echo ' <input type="text" name="chat" value="<font color=FF0000><b>betritt den Raum um <? echo date("H:i"); ?></b></font>">';
echo ' <input type="submit" name="Submit" value="und los!">';
echo ' </form>';
}
function Login() {
echo "Funktion Login aufgerufen";
global $HTTP_SESSION_VARS;
global $chat;
global $nick;
session_start();
session_register("nick", $nick);
?>
<frameset rows="*,120" cols="*">
<frame name="posts" src="cz_chat.php?action=posts&nick=<? echo $nick; ?>&chat=<?php echo $chat; ?>">
<frame name="form" src="cz_chat.php?action=form&nick=<? echo $nick; ?>">
</frameset>
<noframes>
<body>
<p>Diese Seite benötigt Frames die Ihr Brwoser leider nicht unterstützt.</p>
</body>
</noframes>
</frameset>
<?
}
function GetInput() {
global $HTTP_SESSION_VARS;
global $chat;
global $nick;
?>
<body bgcolor="#CCCCCC">
<table border=0 width=100%><tr><td>
<form onSubmit="return doSubmit" name="chatform" method="post" action="cz_chat.php" target="posts">
<input type="text" name="chat" size="40">
<input type="hidden" name="nick" value="<? echo $nick; ?>">
<input type="button" onClick="doSubmit()" name="Submit" value="Chat!">
<input type="image" src="lachen.gif" name="DoFace1" value=" :) " onClick="sendFace(1)">
<input type="image" src="sauer.gif" name="DoFace2" value=" :( " onClick="sendFace(2)">
<input type="image" src="grinz.gif" name="DoFace3" value=" :D " onClick="sendFace(3)">
<input type="image" src="cool.gif" name="DoFace4" value=" :-) " onClick="sendFace(4)">
<select name="col">
<option name=Black>schwarz</option>
<option name=Red>rot</option>
<option name=Green>grün</option>
<option name=Blue>blau</option>
<option name=Orange>orange</option>
</select>
</td>
<td valign=top align=right><a href="http://www.codezilla.at/"><img src="logo.gif" width="216" height="70" border="0" alt="codezilla.at"></a></td></tr></table>
<input type="hidden" name="action" value="posts">
</form>
<script language="JavaScript">
function sendFace(faceNum)
{
switch(faceNum)
{
case 1:
document.chatform.chat.value = ':)';
break;
case 2:
document.chatform.chat.value = ':(';
break;
case 3:
document.chatform.chat.value = ':D';
break;
case 4:
document.chatform.chat.value = ':-)';
break;
}
document.chatform.submit();
document.chatform.chat.value = '';
}
function doSubmit()
{
if(document.chatform.chat.value == '') {
alert('Bitte Text eingeben!');
document.chatform.chat.focus();
return false;
}
document.chatform.chat.value = '<font color="'+document.chatform.col[document.chatform.col.selectedIndex].name+'">'+document.chatform.chat.value+'</font>';
document.chatform.submit();
document.chatform.chat.value = '';
document.chatform.chat.focus();
return true;
}
</script>
<?
}
function ShowAddPosts() {
global $HTTP_SESSION_VARS;
global $chat;
global $nick;
echo '<meta http-equiv="refresh" content="10;URL=cz_chat.php?action=posts&nick=<? echo $nick; ?>">';
if(!empty($chat)) {
$strQuery = "insert into cz_chat values(0, '$chat', '$nick')";
mysql_query($strQuery);
}
$strQuery = "select texta, nick from cz_chat order by id desc limit 20";
$chats = mysql_query($strQuery);
while($chatline = mysql_fetch_array($chats)) {
echo "<b>" . $chatline["nick"] . ":</b> " . swapFaces($chatline["texta"]) . "<br>";
}
$query = "select * from cz_chat";
$result = mysql_query($query);
$num = mysql_num_rows($result);
if ($num >= 10){
$querykilla = "delete from cz_chat";
$resultkilla = mysql_query($querykilla);
}
}
function swapFaces($chatLine) {
$chatLine = str_replace(":)", "<img src='lachen.gif'>", $chatLine);
$chatLine = str_replace(":(", "<img src='sauer.gif'>", $chatLine);
$chatLine = str_replace(":D", "<img src='grinz.gif'>", $chatLine);
$chatLine = str_replace(":-)", "<img src='cool.gif'>", $chatLine);
return $chatLine;
}
?>
<!--
// --------------------------------------------------------------------------
// Dokumentationshinweise:
// Programmname : codezilla.at chat v1.0
// Programmtyp : JavaScript + PHP 4
// Autor : Essl.Bernhard
// Kontakt : admin@codezilla.at
// Erstellt am : 2002 11 06
// Zweck : Chat
// Dieses Skript darf weitergegeben werden solange die Dokumentationshinweise
// erhalten bleiben!
// In diesen Fall wäre es auch nett das Logo stehen zulassen,
// ist aber nicht zwingend :)
// Besuchen Sie www.codezilla.at um weitere freie Skripte zu finden!
// --------------------------------------------------------------------------
-->
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php