Good day!

I have a question. There are 3 tables in the database: user , items and useritems . I need to make a query to the user table and find out if there is such a user in the database, if there is, then output his ИМЯ and all the items that he has, and if there is no user with such a NAME, then we simply output a message that the user is added to database and automatically add an item to it.

In the useritems table I have 3 fields id , uid , and itmid and now I cannot figure out how to add a user there and assign him any item from the items table. Since when I click on the "add" button, only the user is added to the user table.

 INSERT INTO `user` (`uname`) VALUES ('$nambreUsuario'); 

But how to add an item and a user in the useritems table, I will not useritems my mind. And at the same time, it should be that in the user table and the useritems table the user is under the same id

Script output information about the user.

 $(document).ready(function () { $("#resultados").hide(); $('#buscar_usuario').autocomplete({ source: 'ajax.php', select: function (event, ui) { $('#resultados').slideUp('slow', function () { $('#resultados').html('<h2>Информация о пользователе<h2>' + '<img src="' + ui.item.foto + '"/>' + '<strong>Пользователь: </strong>' + ui.item.value + '<br/>' + '<strong>Количество предметов: </strong>' + ui.item.descripcion); }); $('#resultados').slideDown('slow'); } }); }); 

The script output information that the user added:

 $(document).ready(function(){ $('#result').click(function(){ $.post("ajax.php",{"buscar_usuario":$("#buscar_usuario").val()}, $("#resultados").slideToggle("slow"), $(this).toggleClass("active") ) }); 

    1 answer 1

    Something like this:

     mysql_query("INSERT INTO `имя тяблицы` SET `поле`='значение', `поле`='значение';"); 
    • I have such a problem now. In the table it is added but for some reason empty line. Here is my query $ name = $ _POST ['namber_usuarios']; $ sql = "INSERT INTO usuarios (namber_usuarios) VALUES ($ name)" - yurik
    • 1. Run the request handler not directly via ajax, but directly. 2. make echo $sql; before making a request. 3. put ; after assigning the $ sql variable. - DemoS
    • ; do not put - useless. PS Make where you have a query mysql_query ($ query) or die (mysql_error ()); If there is no error, then most likely $_POST['namber_usuarios'] does not come, but if there is, correct it :) - Zowie
    • If not put ; at the end, after assignment, an error will come out, so do not be silly, @AlexWindHope. - DemoS
    • $_POST['namber_usuarios'] does not come. What could be the problem? - yurik