Current location: Hot Scripts Forums » Programming Languages » PHP » php chatscript colour issue


php chatscript colour issue

Reply
  #1 (permalink)  
Old 09-21-04, 06:02 AM
Bantam Bantam is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
php chatscript colour issue

Hi Guys,

hope someone can help me with this problem. In CGI I issue this command inside the script:

PHP Code:

<input type=hidden name=color value=\"$FORM{'color'}\"> 

and whatever colour i pass from a form to the script it captures and keeps however i'm having problems doing this in php. I'm sure its something i'm doing wrong but I'm hoping someone can show me what i've done wrong.

here's my code:

PHP Code:

session_start();


if (!isset(
$_SESSION['color']))
     
$_SESSION['color'] = 0;



$uid = isset($_POST['uid']) ? $_POST['uid'] : $_SESSION['uid']; 
the above is registering my session.

then i've got this on my form part of the script:

PHP Code:

      echo("<table border=0><tr><td valign=middle><input name='msg' size=60></td>") ;

            if (isset(
$_POST["submit"])){
    
$color $_POST["color"];
    
$_SESSION['color'] = $color;
    }
    echo(
"<td valign=middle><input type='hidden' name='color' value='$color'>") ; 

then this is the part that displays on my messages screen:

PHP Code:

<font color='$color' face=verdana size=2><b>{$e[0]}</b> - {$e[2]}<br
but it doesn't seem to pass the colour at any stage and when i view source all i get is the name=color value="0", the value =0 bit should detect the color. What could i be doing wrong? I've posted this on various forums but nobody has really been able to help it seems, I wonder if anyone here could shed some light as to what is wrong? It doesn't seem to be putting a colour into the session although the login page allows them to select a color.
Reply With Quote
  #2 (permalink)  
Old 09-21-04, 07:42 AM
mikaelf mikaelf is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: php[dot]net
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
how do you input the color from the form? what is its file type? cgi with perl or php? your code was fine. the problem is in your form.
__________________
Useful PHP links:
bugs.php.net - for reporting PHP bugs
pear.php.net - PHP extension and application repository
pecl.php.net - get non standard PHP modules, submit yours
www.phpclasses.org - PHP classes repository
Reply With Quote
  #3 (permalink)  
Old 09-21-04, 08:04 AM
Bantam Bantam is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

This is the form that passes the information through once authenticated:

PHP Code:

  <!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Transitional//EN"

    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title> Please Log In for Access </title>
    <meta http-equiv="Content-Type"
      content="text/html; charset=iso-8859-1" />
  </head>
  <body>
  <h1> Login Required </h1>
  <p>You must log in to access this area of the site. If you are
     not a registered user, <a href="signup.php">click here</a>
     to sign up for instant access!</p>
  <p><form method="post" action="<?=$_SERVER['PHP_SELF']?>">
    User ID: <input type="text" name="uid" size="8" /><br />
    Password: <input type="password" name="pwd" SIZE="8" /><br />
Font Color : 
      <SELECT name="color">
      <OPTION SELECTED>black
      <OPTION>blueviolet
      <OPTION>chocolate
      <OPTION>darkgreen
      <OPTION>dimgray
      <OPTION>fuchsia
      <OPTION>maroon
      <OPTION>mediumblue
      <OPTION>navy
      <OPTION>orangered
      <OPTION>purple
      <OPTION>scarlet
      <OPTION>sienna
      <OPTION>teal </SELECT>
<br />
    <input type="submit" name="submit" value="Log in" />
  </form></p>
  </body>
  </html>
it's embeded into a php page.
Reply With Quote
  #4 (permalink)  
Old 09-21-04, 08:41 AM
Bantam Bantam is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Well i've now got it so it pushes the color through the browser and it gives you the colour you want - only problem I have now is that it is showing up all the text in red for one user and if a user logs in with green all the text on his page is green. How can i make it so it shows each individuals color with each post rather than all text in one colour... does that make sense?
Reply With Quote
  #5 (permalink)  
Old 09-21-04, 09:21 AM
mikaelf mikaelf is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: php[dot]net
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Here is the problem:
Code:
Font Color : 
      <SELECT name="color"> 
      <OPTION SELECTED>black 
      <OPTION>blueviolet 
      <OPTION>chocolate 
      <OPTION>darkgreen 
      <OPTION>dimgray 
      <OPTION>fuchsia 
      <OPTION>maroon 
      <OPTION>mediumblue 
      <OPTION>navy 
      <OPTION>orangered 
      <OPTION>purple 
      <OPTION>scarlet 
      <OPTION>sienna 
      <OPTION>teal </SELECT>
Your fields doesn't have value. That's why, after the form is posted, $_POST['color'] never has value beside empty string ('').

It will be different result if you change the code into
Code:
<select name="color"> 
      <option value="#000000" selected>black</option>
      <option value="">blueviolet</option>
      <option value="">chocolate</option>
      <option value="">darkgreen</option>
      <option value="">dimgray</option>
      <option value="">fuchsia</option>
      <option value="">maroon</option>
      <option value="">mediumblue</option>
      <option value="">navy</option>
      <option value="">orangered</option>
      <option value="purple">purple</option>
      <option value="">scarlet</option>
      <option value="">sienna</option>
      <option value="">teal</option>
</select>
where in each value, you may assign color in hex or its name (if its a common color).
__________________
Useful PHP links:
bugs.php.net - for reporting PHP bugs
pear.php.net - PHP extension and application repository
pecl.php.net - get non standard PHP modules, submit yours
www.phpclasses.org - PHP classes repository
Reply With Quote
  #6 (permalink)  
Old 09-21-04, 09:26 AM
Bantam Bantam is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
I got around that part, I moved a piece of my code and it worked however i'm not at the point were it shows all pink for one user or all red text for another rather than the colour of text each user has choosen to indetify themselves.
Reply With Quote
  #7 (permalink)  
Old 09-21-04, 09:31 AM
mikaelf mikaelf is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: php[dot]net
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Bantam
Well i've now got it so it pushes the color through the browser and it gives you the colour you want - only problem I have now is that it is showing up all the text in red for one user and if a user logs in with green all the text on his page is green. How can i make it so it shows each individuals color with each post rather than all text in one colour... does that make sense?
there are two possible actions for this choice:
1. when a user have a post, you check his current color setting and then you manipulate the post by enclosing it with special tag (e.g. [ color="#1A1B1C" ]post content[ / color ]) -> more effective
2. you save user setting in your server and when you display the posts, you join the post table and user setting table -> ineffective and inefficient, user may have changed their setting after he/she posted, also, page loading is longer.
__________________
Useful PHP links:
bugs.php.net - for reporting PHP bugs
pear.php.net - PHP extension and application repository
pecl.php.net - get non standard PHP modules, submit yours
www.phpclasses.org - PHP classes repository

Last edited by mikaelf; 09-21-04 at 09:39 AM. Reason: bbcode parsing
Reply With Quote
  #8 (permalink)  
Old 09-21-04, 09:51 AM
Bantam Bantam is offline
Newbie Coder
 
Join Date: Sep 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
How would i do step 1? I've never tried doing that with php.
Reply With Quote
  #9 (permalink)  
Old 09-21-04, 10:06 AM
4n7hr4x 4n7hr4x is offline
Banned
 
Join Date: Jun 2004
Posts: 237
Thanks: 0
Thanked 0 Times in 0 Posts
You code with many mistakles
change
Code:
<font color='$color' face=verdana size=2><b>{$e[0]}</b> - {$e[2]}<br>
try
Code:
<font color="$color" face=verdana size=2><b>{$e[0]}</b> - {$e[2]}<br></font>
change
Code:
<input type=hidden name=color value="$FORM{'color'}\">
try
Code:
<input type=hidden name=color value="$FORM{'color'}" />
or
Code:
<input type=hidden name=color value=\"$FORM{'color'}\" />

Last edited by 4n7hr4x; 09-21-04 at 10:14 AM.
Reply With Quote
  #10 (permalink)  
Old 09-21-04, 10:09 AM
mikaelf mikaelf is offline
Wannabe Coder
 
Join Date: Jun 2004
Location: php[dot]net
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
ok, here is the example.

Your html form:
Code:
<form action="newpost.php" method="post">
   <input type="text" name="title" />
   <input type="text" name="content" />
   <input type="submit" value="submit" />
</form>
Your php code
PHP Code:

//Check user input

//If all is ok set $ok = 1

if($ok) {
      
$userColor = isset($_SESSION['color']) ? $_SESSION['color'] : '#000000';
      
$content addslashes("[color=$userColor]{$_POST['content']}[/color]");
      
//Add to database
}

//To read, use regex replacement
$content preg_replace('/\[(color)\=([^\]]+)\](.+?)\[\/\1\]/si',"<span style=\"color: \\2;\">\\3</span>",$content);
print 
$content
__________________
Useful PHP links:
bugs.php.net - for reporting PHP bugs
pear.php.net - PHP extension and application repository
pecl.php.net - get non standard PHP modules, submit yours
www.phpclasses.org - PHP classes repository

Last edited by mikaelf; 09-21-04 at 10:13 AM. Reason: bbcode again
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
Mouseover with Single PHP page rjwebgraphix PHP 7 09-16-04 05:15 PM
php with Apache in windows eDevil PHP 3 08-08-04 12:03 AM
php or apache issue? lokey PHP 7 03-08-04 11:55 PM
100 Web Templates & 10 PHP Scripts for sale! HostersUK.co.uk General Advertisements 0 01-10-04 12:31 AM


All times are GMT -5. The time now is 04:30 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.