sasori Posted April 23, 2010 Share Posted April 23, 2010 here's the screen shot of the error I don't really know what's going on here's the chat.php code <?php require_once("chat.class.php"); $mode = $_POST['mode']; $id = 0; $chat = new Chat(); if($mode == 'SendAndRetrieveNew') { $name = $_POST['name']; $message = $_POST['message']; $color = $_POST['color']; $id = $_POST['id']; if($name != '' && $message != '' && $color != '') { $chat->postMessage($name,$message,$color); } } elseif($mode == 'DeleteAndRetrieveNew') { $chat->deleteMessages(); } elseif($mode == 'RetrieveNew') { $id = $_POST['id']; } if(ob_get_length()) ob_clean(); header('Expires: Mon, 26 July 1997 05:00:00 GMT'); header('Last-Modified: '. gmdate('D, d M Y H:i:s'). 'GMT'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); header('Content-Type: application/json'); echo json_encode($chat->retrieveNewMessages($id)); ?> and here's the chat.class.php <?php require_once('config.php'); require_once('error_handler.php'); class Chat { private $mMysqli; function __construct() { $this->mMysqli = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_DATABASE); } public function __destruct() { $this->mMysqli->close(); } public function deleteMessages() { $query = 'TRUNCATE TABLE chat'; $result = $this->mMysqli->query($query); } public function postMessage($name,$message,$color) { $name = $this->mMysqli->real_escape_string($name); $message = $this->mMysqli->real_escape_string($message); $color = $this->mMysqli->real_escape_string($color); $query = 'INSERT INTO chat(posted_on, user_name,message,color)'; $query .= 'VALUES(NOW(),"$name","$message","$color")'; $result = $this->mMysqli->query($query); } public function retrieveNewMessages($id=0) { $id = $this->$mMysqli->real_escape_string($id); if($id>0) { $query = 'SELECT chat_id, user_name, message, color, DATE_FORMAT(posted_on, "%Y-%m-%d %H:%i:%s") AS posted on '. 'FROM chat where chat_id > '. $id . 'ORDER BY chat_id ASC'; } else { $query = 'SELECT chat_id, user_name, color, posted_on FROM'. '{SELECT chat_id, user_name, message, color, '. 'DATE_FORMAT(posted_on,"%Y-%m-%d %H:%i:%s) AS posted_on'. 'FROM chat '. 'ORDER BY chat_id DESC'. 'LIMIT 50) AS Last50'. 'ORDER BY chat_id ASC'; } $result = $this->mMysqli->query($query); $response = array(); $response['clear'] = $this->isDatabaseCleared($id); $response['messages'] = array(); if($result->num_rows) { while($row = $result->mysqli_fetch_array(MYSQLI_ASSOC)) { $message = array(); $message['id'] = $row['chat_id']; $message['color'] = $row['color']; $message['name'] = $row['user_name']; $message['time'] = $row['posted_on']; $message['message'] = $row['message']; array_push($response['messages'],$message); } $result->close(); } return $response; } private function isDatabaseCleared($id) { if($id > 0) { $check_clear = 'SELECT count(*) old FROM chat where chat_id <= $id'; $result = $this->mMysqli->query($check_clear); $row = $result->fetch_array(MYSQLI_ASSOC); if($row['old'] == 0) return 'true'; return 'false'; } return 'true'; } } ?> and here's the html page <html> <head> <title>testing chat.php</title> </head> <body> <form action="chat.php" method="post"> Mode: <input type="text" name="mode" size="50" value="SendAndRetrieveNew" /> <br /> Name: <input type="text" name="name" size="50" /> <br /> Message: <input type="text" name="message" size="50" /> <br /> Color: <input type="text" name="color" size="50" value="#000000"/> <br /> ID: <input type="text" name="id" size="50" /> <br /> <input type="submit" /> </form> </body> </html> and here's my error_handler.php <?php set_error_handler('error_handler',E_ALL); function error_handler($errNo,$errStr,$errFile,$errLine) { if(ob_get_length()) ob_clean(); $error_message = 'ERRNO: '. $errNo. chr(10). 'TEXT: '. $errStr. chr(10). 'LOCATION: '. $errFile. chr(10). ', line '. $errLine; echo $error_message; exit; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/ Share on other sites More sharing options...
TeddyKiller Posted April 23, 2010 Share Posted April 23, 2010 I dont think it's a real problem. Its just cause you have error reporting on. Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047082 Share on other sites More sharing options...
sasori Posted April 23, 2010 Author Share Posted April 23, 2010 I dont think it's a real problem. Its just cause you have error reporting on. ok, so I added error_reporting(0); right at the top of the chat.php file this time, when i click the submit button of the html file firefox is downloading the script LOL, wtf Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047084 Share on other sites More sharing options...
TeddyKiller Posted April 23, 2010 Share Posted April 23, 2010 set_error_handler('error_handler',E_ALL); error_handler.php Thats the problem. It's set as E_ALL Or, in class.chat.php you can remove this line. require_once('error_handler.php'); Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047086 Share on other sites More sharing options...
sasori Posted April 23, 2010 Author Share Posted April 23, 2010 weird..i just commented the require_once('error_handler.php'); from the chat.class.php file then i refresh my browser and submitted the data...yeah it saves the data in the db but ff is still prompting me to download the chat.php file LOL,, anyway to solve this ? Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047091 Share on other sites More sharing options...
TeddyKiller Posted April 23, 2010 Share Posted April 23, 2010 Is the filename actually chat.php without a typo maybe chat.phps or something. Does it prompt the download in I.E? What changes have you made in chat.php for it to lead to a possible download prompt. Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047094 Share on other sites More sharing options...
sasori Posted April 23, 2010 Author Share Posted April 23, 2010 Is the filename actually chat.php without a typo maybe chat.phps or something. Does it prompt the download in I.E? What changes have you made in chat.php for it to lead to a possible download prompt. yeah, i tried in I.E(,, and it does the same thing too, i didn't alter anything in the chat.php file, only the chat.class.php but no, am 101% sure all my files got .php extension except for the test.html ofcourse. any idea now why chat.php is being downloaded when form is submitted ? Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047099 Share on other sites More sharing options...
TeddyKiller Posted April 23, 2010 Share Posted April 23, 2010 You could try changing the submit button. <input type="submit" name="submit" value="submit" /> Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047112 Share on other sites More sharing options...
sasori Posted April 23, 2010 Author Share Posted April 23, 2010 changing the submit button didn't helped at all .. hmmmn...any other idea ? Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047114 Share on other sites More sharing options...
TeddyKiller Posted April 23, 2010 Share Posted April 23, 2010 Hmm.. Has it ever worked before? Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047121 Share on other sites More sharing options...
sasori Posted April 23, 2010 Author Share Posted April 23, 2010 Hmm.. Has it ever worked before? no, i just created it today, and eventually completed it..it's the first time i tested it. and it is behaving real bad.. i know i might sound lame, but..did you try the same code in your local server sir ? Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047124 Share on other sites More sharing options...
TeddyKiller Posted April 23, 2010 Share Posted April 23, 2010 No I haven't. Do you have a version of this on the web so I can view it? Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047130 Share on other sites More sharing options...
sasori Posted April 23, 2010 Author Share Posted April 23, 2010 none sir, my webhosting account doesn't allow ajax chat..actually this code isn't fully complete yet, it's supposed to be an ajax stuff Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047133 Share on other sites More sharing options...
TeddyKiller Posted April 23, 2010 Share Posted April 23, 2010 none sir, my webhosting account doesn't allow ajax chat..actually this code isn't fully complete yet, it's supposed to be an ajax stuff Seriously?! Ajax is PHP + Javascript.. all paid hosts must allow that.. quite a few free hosts do too like 000webhosting. How are you testing the code? Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047137 Share on other sites More sharing options...
sasori Posted April 23, 2010 Author Share Posted April 23, 2010 ah yes sir, am not yet on the javascript part. i need to make this work first before i jump to the js stuff.. i haven't get rid of the auto download of the chat.php file yet LOL ..btw, my hosting account is free also but they have rules as such Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047143 Share on other sites More sharing options...
TeddyKiller Posted April 23, 2010 Share Posted April 23, 2010 Wow that sucks. Try going over to 000webhost. You'll be able to upload your script live... I can't really test it out myself. It uses a Database and thats too much hastle. Sorry. Maybe someone else may know the problem. Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047146 Share on other sites More sharing options...
Ken2k7 Posted April 23, 2010 Share Posted April 23, 2010 Wow! That hosting doesn't allow two of the top commercial messaging board software? That's so lame. Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047147 Share on other sites More sharing options...
TeddyKiller Posted April 23, 2010 Share Posted April 23, 2010 Wow! That hosting doesn't allow two of the top commercial messaging board software? That's so lame. I think they don't like people talking to others.. Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047148 Share on other sites More sharing options...
sasori Posted April 23, 2010 Author Share Posted April 23, 2010 arghhh... i found out i got an old account in 000webhost...now i was trying to create an account to upload my scripts..it says error , , we will setup your account manually..LOL...nevermind..I'll just mark this thread as solved,,thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/199505-undefined-index-help/#findComment-1047168 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.