1
Hello, good night to all.
This is my first question in the forum and I would like to solve a problem with my small web application.
This is a work of end of semester of my course, and I need to create a small system of registration of products, using the functions of Insert, Delete, Change and List with PHP
and MySQL
.
Before detailing the problem, I will specify how the system is.
When registering a new product, a modal
, and then enter all the data related to the product. After inserting, the registered product is added to a div
, where it contains a box
with the image and product information.
I created a input
for the search of the products, however, when I enter the name of a product, it duplicate.
<div id="Conteudo">
<form>
<input id="Pesquisa" type="search" name="Pesquisar">
<input id="Buscar" type="submit" name="Enviar" />
<!-- Código PHP -->
</form>
<div id="Produto">
<!-- Descrição do produto -->
<!-- Código PHP para exibir Produto após seu registro -->
</div>
</div>
<!-- Código PHP que realiza a busca no banco e lista o resultado -->
<?php
if(isset($_POST['Enviar'])){
$Pesquisar = $_POST['Pesquisar'];
if($Pesquisar != NULL){
$request = mysql_query("SELECT * FROM `banco`.`tabela` WHERE nome = '$Pesquisar' ");
echo "
<div id="Produto">
<!-- Conteúdo -->
</div>
";
?>
I simplified the code because there are many lines considering the whole form, the PHP
and the MySQL
. I’m pretty sure the problem is because the codes PHP
meet in different locations. I researched more about it and saw solutions that worked with OOP
.
I intend to delve into this paradigm. However, I need your help to finish this work.
This is the problem: When searching, instead of just displaying what was requested, it duplicates the search and stays out of the layout (I think it’s because the codes PHP
meet in different locations).
Forgive me for asking. Thanks in advance for your attention.
first try to put in the form the method Voce is using which in case would be <form method="POST"> . And then test the variable to search if it is even taking the value of the input field
– LocalHost
hi, imagining that the code is correct, checks the places where you clean the
$request
and the$Pesquisar
((unset($request);
or$request = '';
)) []’s– Art
mysql_functions have already been removed from php7 so it is not appropriate to use them. Only with this snippet of code do you not notice the problem.
– rray
@Localhost, actually already found the syntax of
POST
in the application. Working up to the display. But I just need to exquisite the results, not duplicate them. Excuse me for not having put them in the example of the question.– Mikael Araki
@Art, truth, there was not thinking of zeroing the values. But this will work with codes
php
in different places?– Mikael Araki
@rray, I understand. I appreciate the guidance.
– Mikael Araki
@Mikaelaraki you can demonstrate what happens using this website? This makes it easier to identify what is happening. Only with this piece of code, as already commented, we can not identify the error.
– Rafael Withoeft
@Rafaelwithoeft, I’ll be seeing to it for you. Just a moment.
– Mikael Araki
@Rafaelwithoeft, I won’t need more. I managed to solve with the help of a colleague. Thank you very much!
– Mikael Araki