Please help with the code. There are 2 tables in MYSQL: messages
and dialogs
The script below should add the data about the sender by id and recipient, as well as a message and a couple of parameters, but problems with adding messages to the table.
<?php session_start(); include('config.php'); if(isset($_POST['send'])){ $result = mysql_query("SELECT * FROM `messages` WHERE `from_id` = '".$_SESSION['id']."' AND `to_id` = '".$_GET['mes']."' LIMIT 5",$mysql_connect) or die(mysql_error()); $count = mysql_num_rows($result); if($count=0) { ### mysql_query(" INSERT INTO `messages` (`from_id`,`to_id`) VALUES ('".$_SESSION['id']."','".$_GET['mes']."') ",$mysql_connect) or die("ERROR: ".mysql_error()); $result = mysql_query("SELECT * FROM `messages` WHERE `from_id` = '".$_SESSION['id']."' AND `to_id` = '".$_GET['mes']."' LIMIT 1",$mysql_connect) or die(mysql_error()); while($data = mysql_fetch_array($result)){ $dialog_id=$data['dialog_id']; } mysql_query(" INSERT INTO `dialogs` (`dialog_id`,`messages`,`date`) VALUES ('".$dialog_id."','".$_POST['messages']."','30.09.1923') ",$mysql_connect) or die("ERROR: ".mysql_error()); } else{ $result = mysql_query("SELECT * FROM `messages` WHERE `from_id` = '".$_SESSION['id']."' AND `to_id` = '".$_GET['mes']."' LIMIT 1",$mysql_connect) or die(mysql_error()); while($data = mysql_fetch_array($result)){ $dialog_id=$data['dialog_id']; } mysql_query(" INSERT INTO `dialogs` (`dialog_id`,`messages`,`date`) VALUES ('".$dialog_id."','".$_POST['messages']."','30.09.1923') ",$mysql_connect) or die("ERROR: ".mysql_error()); } } ?> <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Документ без названия</title> </head> <body> <form action="test.php" method="post"> <textarea name="messages" cols="" rows=""></textarea> <input type="submit" name="send" id="send" value="Отправить" /> </form> </body> </html>