I got some strange problems. Using my class i connecting to mysql, connection is successful but when i call a function its not works. Im using my own error handler and if i got in php some error on this line it using exit; i have used echo before calling function and after page is not killing (it means that php work successful) mysql query i have checked its works too but when im using return 'some text'; its not returning. any suggestions why function is not working?
my class:
<?php
include('../config.php');
include('../chat_error_handler.php');
class Chat {
private $mysqli;
var $con;
//Constructor open db conn
function __construct() {
$this->mysqli = new mysqli('localhost', 'root', '', 'test');
}
//destructor close db conn
function __destruct() {
$this->mysqli->close();
}
public function postNewMessage($user_name, $message, $color, $room_id) {
$user_name = $this->mysqli->real_escape_string($user_name);
$message = $this->mysqli->real_escape_string($message);
$color = $this->mysqli->real_escape_string($color);
$room_id = $this->mysqli->real_escape_string($room_id);
$query = 'INSERT INTO chat (posted_on, account, message, color, room_id)' .
' VALUES (NOW(), "'.$user_name.'", "'.$message.'", "'.$color.'", "'. $room_id .'")';
$result = $this->mysqli->query($query);
return 'Pranesimas';
$result->close();
}
My php im using to debug:
<?php
include('core/chat.class.php');
include('chat_error_handler.php');
$chat = new Chat();
$message = 'testas';
echo $message.'<br/>';
$chat->postNewMessage('testing', $message, '#000000', 1);
echo '<br/>'.$message;
?>
returnstatement in a function isn't very useful."'.$color.', should be"'. $color .'"- regardless, if an MySQL insert isn't working, always attempt to get the Query String and try yourself in PHPMyAdmin or your MySQL Command line, then you'll see errors