Second Insert in mysql not work

Discuss coding issues, and scripts related to PHP and MySQL.
mluci12
Posts: 39

Second Insert in mysql not work

Hello!Have you any idea why this don't work?
Please!

Code: Select all

<?php
require('layout2.php'); 
$user = trim($_GET['user']);
header('Content-type: text/html; charset=utf-8');
session_start();

$mesaj = '';  

        // Variabila folosita pt. mesajul ce va fi afisat pt. utilizator
$nume2=$_SESSION['username'];
// Se verifica daca sunt primite datele de la formular
if (isset($_POST['message']) && isset($_POST['message'])) {
  // Se filtreaza datele pt. eliminare posibile spatii exterioare si tag-uri
  $_POST = array_map("trim", $_POST);
  $_POST = array_map("strip_tags", $_POST);

  // Se verifica daca "magic_quotes_gpc()" este setat ON
  // Daca e ON, se aplica stripslashes() pentru a nu se adauga de 2 ori '\' cand va fi aplicat "mysql_real_escape_string()"
  if(get_magic_quotes_gpc()) { $_POST = array_map("stripslashes", $_POST); }

  // Daca nu exista nici un mesaj de eroare, filreaza datele cu mysql_real_escape_string() si le adauga in baza de date
  // Altfel, in cazul vreunei erori, adauga in variabila $mesaj
  if (!isset($eroare)) {
    include('conn.php');         // Include fisierul pt. conectare-selectare baza de dat

    // Se aplica functia de filtrare mysql_real_escape_string()

       $message = $_POST['message'];

    // Acum se adauga mai in siguranta aceste date in MySQL
    $sql = "INSERT INTO `conversatii` (`user-i`,`user-p` ) VALUES ('$nume2', '$user')";
  if (mysql_query($sql, $conn)) {
    $mesaj = '<div class="alert alert-success alert-dismissable">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                    <h4>  <i class="icon fa fa-check"></i> Thank you!We can view more details in My Conversation</h4>
                    
                  </div>';
    $nume = '';  $email = '';
    $last_id = $conn->insert_id;
    $sql2 = "INSERT INTO `mesaje` (`user-i`,`user-p` ,`mesaj` , `id-` ) VALUES ('$nume2', '$user' ,` $message` , ` $last_id`)";
  }
    else $mesaj = '<font color="red">Datele nu au putut fi adaugate '. mysql_error(). '</font>';

  mysql_close($conn);
  }
  else $mesaj = '<font color="red">'. implode('<br />', $eroare). '</font>';
}
echo $mesaj;
- Dont't work the second insert..first work good!

Admin
Hi,
The second Insert, $sql2, is not sent to mysql (with mysql_query() ).
Also, the second insert seems wrong. Maybe this is correct:

Code: Select all

$sql2 = "INSERT INTO `mesaje` (`user-i`,`user-p` ,`mesaj` , `id` ) VALUES ('$nume2', '$user' ,'$message', $last_id)";
- Then, apply the function to send it to mysql.

Similar Topics