Never touched PHP before

hi all, I have be charged with setting up a quick and dirty chat program. I have installed php, I found a chat php script, set it up, I did get past the Notice undefined veriables issue, now the only problem gett the script to post. when you hit submit nothing gets displayed.

here is the script:

<? // if name is not entered, present the form again if(!$chatname) { print_form(); exit; }; // do not post an empty message, unless it is a smiley $is_smile = "smileys/default.gif"; if(!$message && ($smile == $is_smile)) { print_form_nameset(); exit; }; // set up timestamp variables $time = date("H:i d/m"); $rightnow = time(); $lasttenmin = $rightnow - 600 ; // read data files into arrays $message_array = file("messages.htm"); $history_array = file("history.htm"); $online_array = file("online.txt"); // get the last 10 messages for ($counter = 1; $counter < 10; $counter++) { $old_messages .= $message_array[$counter]; } // get the last 200 messages from history for ($counter = 1; $counter < 200; $counter++) { $old_history .= $history_array[$counter]; } // stuff for the online things here foreach ($online_array as $user_on) { $fields = explode(",",$user_on); // if time stored is less than (older) than 10 mins ago, strip it out if( $fields[0] < $lasttenmin ){ break; } // if name stored is current chatname, strip it out if( $fields[1] == "$chatnamen" ){ break; } // otherwise put the data back into a nice package. $updated .= $user_on; } // record that we are online $updated .= "$rightnow,$chatnamen"; $online = stripslashes($updated); // then we need to write out the new online data file $open_file = fopen("online.txt", w); fputs($open_file, $online); fclose($open_file); // prepare the format of the new message $chatname = htmlspecialchars($chatname); $message = htmlspecialchars($message); $new_message = " $time $chatname [-] $message

n "; // set up header and footer for the messages and history page $header = "". "". "". "

". " n"; $footer = "


". ""; // write the new message file $open_file = fopen("messages.htm", "w"); fputs($open_file, $header); fputs($open_file, stripslashes($new_message)); fputs($open_file, $old_messages); fputs($open_file, $footer); fclose($open_file); // write the history file $open_file = fopen("history.htm", "w"); fputs($open_file, $header); fputs($open_file, stripslashes($new_message)); fputs($open_file, $old_history); fputs($open_file, $footer); fclose($open_file); // thats it for the main part, the functions follow print_form_nameset(); function print_form() { global $chatname; global $PHP_SELF; echo <<<FORM1

Screen Name : Text Colour : black blue yellow red green White   Emotions : Happy Grin Ha Ha Yawn Sleep Angry V Angry
Message :  
FORM1; } function print_form_nameset() { global $myfont; global $chatname; global $PHP_SELF; echo <<<FORM2

Screen Name : $chatname
  Emotions : Happy Grin Ha Ha Yawn Sleep Angry V Angry
Message :  
FORM2; } ?>

Register globals being off is probably your problem, this is the most common problem when passing form data.

Try accessing your variables using the $_POST superglobal array.

$chatname = $_POST[‘chatname’];
$smile = $_POST[‘smile’];
$myfont = $_POST[‘myfont’];
$message = $_POST[‘message’];

:)

I’m getting closer, Thank you for your reply. It still isn’t working but I think it is because I have put the below info in the in the wrong place.

$chatname = $_POST[‘chatname’];
$smile = $_POST[‘smile’];
$myfont = $_POST[‘myfont’];
$message = $_POST[‘message’];

I’m not sure where is should go, but I am working on that.

Thank you again

You need to declare the variables BEFORE they are used. Directly beneath your opening <? tag should be fine.

Its working thank you very much! :D

No problem, you`re welcome. :)

May want to kick down the PHP error reporting level too. PHP doesn’t require you to delcare vars by default, thats why its so easy and fast to program with.

Keith

thank you I have turned down the error reporting and things are working great. I have never worked with PHP until now and so far I’m really enjoying it. This Forum is a great place to learn and get tips. Keep up the good work everyone.

Sherry aka Goosemar

Sponsor our Newsletter | Privacy Policy | Terms of Service