Mysql
 sql >> Baza danych >  >> RDS >> Mysql

dane wprowadzone w polu tekstowym nie wejdą do bazy danych zaprojektowanej przy użyciu php i mysqli

Spróbuj tego:

<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:Jak wstawić wiele rekordów z autoinkrementacją tego samego ID

  2. Dołącz do dwóch tabel i uzyskaj najniższą cenę z wieloma warunkami (wiele sku)

  3. Najlepszy sposób na usunięcie wartości z pola SET?

  4. cakephp dodawanie rekordu z poprawionymi niektórymi parametrami

  5. mysql liczy się tylko dla różnych wartości w połączonym zapytaniu