Jump to content

[SOLVED] some simple help with $= (please help)


mybluehair

Recommended Posts

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

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");

}

?>

 

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.