mybluehair Posted November 13, 2007 Share Posted November 13, 2007 ok, so im making a chat room using only php and mysql, and all on one page, theres a message form, and a insert into DB code (for whatever they entered in message form) and a display code, to display all the messages. and so i just added a member feature. and whats suppose to happen is $message is suppose to equal first what your username is, then what you entered into the messge form, so when i display it, it will look like "andrew32: hi mom" so heres my little code for that: $message= $_SESSION['s_username']; $_POST['message']; now i have tried that plenty of other ways, all with the outcome of a mysql error. this is the only one that dosnt create a mysql error. but it dosnt regonize the message, only there username. so how do i write this out so that it will do what i want it to. here is my full code if you need it: <? session_start(); include 'config.php'; if($_SESSION['s_logged_n'] == 'true'){ $query3="SELECT * FROM settings"; $result3=mysql_query($query3); $name=mysql_result($result3, "", "chatname"); $message= $_SESSION['s_username']; $_POST['message']; echo "Welcome to $name chatroom"; if($_SESSION['user_level'] == 2){ echo "<center><a href=\"ap.php\">Admin panel</a></center><br>"; } echo " <form action=\"allinone.php\" method=\"post\"> <br> chat message:<br> <textarea rows=\"12\" cols=\"65\" name=\"message\" id=\"message\"></textarea> <br><br> <input type=\"submit\"><br>"; if ($_POST['message'] == '') { echo ""; } else { $query1 = "INSERT INTO contacts VALUES ('', '$message', NOW())"; mysql_query($query1); } echo '<hr>'; $query="SELECT * FROM `contacts` ORDER by 'datetime' DESC "; $result=mysql_query($query); $num=mysql_numrows($result); echo "<b><center>chats:</center></b><br><br><br>"; $i=0; while ($i < $num) { $message=mysql_result($result,$i,"message"); echo "<b>$message</b><br><hr><br>"; $i++; } mysql_close($l); } else { header("Location: login.php"); } ?> Link to comment https://forums.phpfreaks.com/topic/77091-solved-some-simple-help-with-please-help/ Share on other sites More sharing options...
darkfreaks Posted November 13, 2007 Share Posted November 13, 2007 <?php $message= $_SESSION['s_username']|| $_GET['message'];?> Link to comment https://forums.phpfreaks.com/topic/77091-solved-some-simple-help-with-please-help/#findComment-390420 Share on other sites More sharing options...
mybluehair Posted November 13, 2007 Author Share Posted November 13, 2007 <?php $message= $_SESSION['s_username']|| $_GET['message'];?> yay. thanks Link to comment https://forums.phpfreaks.com/topic/77091-solved-some-simple-help-with-please-help/#findComment-390426 Share on other sites More sharing options...
darkfreaks Posted November 13, 2007 Share Posted November 13, 2007 if it works clicked solved topic Link to comment https://forums.phpfreaks.com/topic/77091-solved-some-simple-help-with-please-help/#findComment-390428 Share on other sites More sharing options...
mybluehair Posted November 13, 2007 Author Share Posted November 13, 2007 sorry, it didnt work. now, when i enter something into the message form, and click submit, it displayes it as "1" new code: <? session_start(); include 'config.php'; if($_SESSION['s_logged_n'] == 'true'){ $query3="SELECT * FROM settings"; $result3=mysql_query($query3); $name=mysql_result($result3, "", "chatname"); $message= $_SESSION['s_username']|| $_GET['message']; echo "Welcome to $name chatroom"; if($_SESSION['user_level'] == 2){ echo "<center><a href=\"ap.php\">Admin panel</a></center><br>"; } echo " <form action=\"allinone.php\" method=\"post\"> <br> chat message:<br> <textarea rows=\"12\" cols=\"65\" name=\"message\" id=\"message\"></textarea> <br><br> <input type=\"submit\"><br>"; if ($_POST['message'] == '') { echo ""; } else { $query1 = "INSERT INTO contacts VALUES ('', '$message', NOW())"; mysql_query($query1); } echo '<hr>'; $query="SELECT * FROM `contacts` ORDER by 'datetime' DESC "; $result=mysql_query($query); $num=mysql_numrows($result); echo "<b><center>chats:</center></b><br><br><br>"; $i=0; while ($i < $num) { $message=mysql_result($result,$i,"message"); echo "<b>$message</b><br><hr><br>"; $i++; } mysql_close($l); } else { header("Location: login.php"); } ?> Link to comment https://forums.phpfreaks.com/topic/77091-solved-some-simple-help-with-please-help/#findComment-390429 Share on other sites More sharing options...
Aureole Posted November 13, 2007 Share Posted November 13, 2007 <?php $message = $_SESSION['s_username']; $message .= $_GET['message']; ?> Link to comment https://forums.phpfreaks.com/topic/77091-solved-some-simple-help-with-please-help/#findComment-390431 Share on other sites More sharing options...
mybluehair Posted November 13, 2007 Author Share Posted November 13, 2007 <?php $message = $_SESSION['s_username']; $message .= $_GET['message']; ?> thanks that worked. just 1 more thing. if i wanted to make the username a different color, and also add a little ":" after the user name, how would i do that inside $message Link to comment https://forums.phpfreaks.com/topic/77091-solved-some-simple-help-with-please-help/#findComment-390434 Share on other sites More sharing options...
darkfreaks Posted November 13, 2007 Share Posted November 13, 2007 <?php $message = $_SESSION['s_username']; echo ":"; $message .= $_GET['message']; ?> Link to comment https://forums.phpfreaks.com/topic/77091-solved-some-simple-help-with-please-help/#findComment-390437 Share on other sites More sharing options...
Aureole Posted November 13, 2007 Share Posted November 13, 2007 <?php $message = '<span style="color:red;">'.$_SESSION['s_username'].'</span>: '; $message .= $_GET['message']; ?> Link to comment https://forums.phpfreaks.com/topic/77091-solved-some-simple-help-with-please-help/#findComment-390438 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.