Jump to content

PHP and MySQL Debug


dcole.ath.cx

Recommended Posts

Can someone look through this code, it looks okay to me. There maybe something wrong with "mysql_fetch_row($result)" ... which is in the 1nd "else" right before the 2nd "if".

<?// Connect to MySQL using this data:$dbhost = 'localhost';$dbuser = 'root';$dbpass = '';$dbname = 'chat';// "chat" is name of MySQL table// Connect to MySQL and a table within it$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');mysql_select_db($dbname);// Get message and timeheader('Content-Type: application/xml');$msg = htmlentities(trim(stripslashes($_REQUEST['msg'])));$ts = time();$answer = '';$front = substr($msg, 6);if($front == 'learn:'){	// insert data into MySQL	$back = strstr($msg, 'learn:');	list($message, $response) = explode("<><><>", $back);	$query = "INSERT INTO chat (message, response) VALUES ($message, $response)";	mysql_query($query) or die('Error, insert query failed');	$answer = 'Thank you, data has been learned.';}else {	$query  = 'SELECT message, response FROM chat';	$result = mysql_query($query);	while(list($message,$response)= mysql_fetch_row($result)) {		if ($message == $msg) {			$answer = $response;		}		else {			$answer = 'I am sorry my responses are limited.';		}	}}mysql_close($conn);$msg = $answer;print ("<?xml version=\"1.0\"?>");print ("<test timestamp=\"$ts\">");print ("<message>$msg</message>");print ("</test>");?>

Thanks

Link to comment
Share on other sites

Short tags are enabled on the server so this line is confusing PHP:print ("<?xml version=\"1.0\"?>");You can replace it with this:print ("<" . "?xml version=\"1.0\"?" . ">");Other then that the code looks good.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...