Data Entered In Text Area Wont Enter Into Database Designed Using Php And Mysqli
I am trying to create a private messaging system in which user sends message to another user and that content is inserted into database..Iam using a random number called hash to id
Solution 1:
Try this:
<html><head><title>convo</title></head><body><div><?phpinclude'connect.php'; ?><?phpinclude'message_title_bar.php'; ?><?phpinclude'functions.php'; ?><?phpinclude'title_bar.php'; ?><?php$my_id = $_SESSION['user_id'];
$connect = mysqli_connect('localhost', 'root', '', 'php_mysql_login_system');
if (mysqli_connect_errno()) echo"Failed to connect to MySQL: " . mysqli_connect_error();
if (isset($POST['message']) && !empty($_POST['message']) && isset($_SESSION['hash']) && !empty($_SESSION['hash'])) {
$hash = $_SESSION['hash'];
$new_message = $_POST['message'];
mysqli_query($connect, "INSERT INTO messages VALUES('', '$hash', '$my_id', '$new_message')");
header("Location: " . "http://" . $_SERVER['HTTP_HOST'] . "/conversations.php?hash=".$hash);
exit;
}
if (isset($_GET['hash']) && !empty($_GET['hash'])) {
$_SESSION['hash'] = $_GET['hash'];
$hash = $_SESSION['hash'];
$message_query = mysqli_query($connect, "SELECT from_id, message FROM messages WHERE group_hash='$hash'");
while ($run_message = mysqli_fetch_array($message_query)) {
$from_id = $run_message['from_id'];
$message = $run_message['message'];
$run_user = mysqli_fetch_array(mysqli_query($connect, "SELECT username FROM users WHERE id='$from_id'"));
$from_username = $run_user['username'];
echo"<p><b>$from_username</b><br />$message</p>";
}
?><formmethod='post'><labelfor="message">Enter message:</label><textareaname='message'id="message"rows='7'cols='60'></textarea><br/><br/><inputtype='submit'value="send message"/></form><?php
} else {
echo"<b>select conversation</b>";
$query_string = "SELECT `hash`, `user_one`, `user_two` FROM message_group WHERE user_one='$my_id' OR user_two='$my_id'";
$get_con = mysqli_query($connect, $query_string);
while ($run_con = mysqli_fetch_array($get_con)) {
$hash = $run_con['hash'];
$user_one = $run_con['user_one'];
$user_two = $run_con['user_two'];
if ($user_one == $my_id) {
$select_id = $user_two;
} else {
$select_id = $user_one;
}
$query = "SELECT username FROM users WHERE id='$select_id'";
$run_user = mysqli_fetch_array(mysqli_query($connect, $query));
$select_username = $run_user['username'];
echo"<p><a href='?hash=".$hash."'>$select_username</a></p>";
}
}
?>
Post a Comment for "Data Entered In Text Area Wont Enter Into Database Designed Using Php And Mysqli"