Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

data yang dimasukkan di area teks tidak akan masuk ke database yang dirancang menggunakan php dan mysqli

Coba ini:

<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>";
    }
}
?>




  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. MySQL Gabung berdasarkan YEAR () pengindeksan - Kolom tambah atau Kolom yang Dihasilkan

  2. Berapa persentase pengguna yang berpartisipasi setiap hari (SQL Query)

  3. Bagaimana menjalankan database pengujian Django hanya di memori?

  4. Menginstal MySQL di CentOS 7

  5. Bagaimana cara membuat mysqli bekerja dengan DELIMITER dalam pernyataan SQL?