Mysql
 sql >> Base de données >  >> RDS >> Mysql

les données saisies dans la zone de texte n'entreront pas dans la base de données conçue à l'aide de php et mysqli

Essayez ceci :

<html>
<head><title>convo</title></head>
<body>
<div>
<?php include 'connect.php'; ?>
<?php include 'message_title_bar.php'; ?>
<?php include 'functions.php'; ?>
<?php include '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>";
    }
    ?>
    <form method='post'>
        <label for="message">Enter message:</label>
        <textarea name='message' id="message" rows='7' cols='60'></textarea>
        <br/><br/>
        <input type='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>";
    }
}
?>