1
Greetings!
I have a page in which contains a 'search' field, when typing something, the field returns similar names.
Example: If I type "a" it returns me "amateur, lover, Amarildo, amoxilina, attendant, allocate." and etc.
And there is a button in index.php that serves to send such requests
The question is, if I type "-" in the field, it will not return me anything, because there is no such value in the database, however, I can still send the requests (which would only be to save the names that appear on a page), in this case, as there is no name similar to "-", it sends the request, filling a page field with a null value (blank).
I wanted to somehow prevent it being possible to send requests if there was no such value within the database, one way I thought was:
This is the button code, which allows me to send the request
<button> Enviar<i class="zmdi zmdi-arrow-right"></i></button>
If I can check the upload field, if it is incorrect, I could disable the button in such a way
<button disabled=""> Enviar<i class="zmdi zmdi-arrow-right"></i></button>
Is there any way to make this change to html code via php? or some better method to handle such an operation..?
Note: This is the only button on the page, so it wouldn’t be a specific button (because using a code specifying the change of the button status would certainly disable everyone on the page)
Edit1: "index.php" connects to the database and handles it by selecting it to the search field in such a way:
$query ="SELECT * FROM bancod WHERE id like '" . $_POST["keyword"] . "%' ORDER BY id LIMIT 0,9";
$result = mysqli_query($con, $query);
$count= mysqli_num_rows($result);
if($count < 1){
echo "Esse valor não existe no banco de dados ";
}
So it already checks the existence of the entered value, whether or not it contains in the database. If it does not exist, it prints me "This value does not exist in the database". However, I can still send the request by clicking on the button, but as I said, it fills the fields nullally, all blank ): and I just wanted to prevent it from being possible to send it
"I wanted to somehow prevent it being possible to send requests if there is no such value within the database"... how will you know that there is no value in the database without making a request?
– Sam
@Sam Edited the topic, "Edit1:" answers the question
– Lucas
The only thing I can think of, from what I understand, is to disable the button if the input field is empty or create some criteria in the frontend. For example, check if the field contains only letters etc...
– Sam
This would be a good one, I thought about it, but being more direct, the field will only have numerical searches, example: "20200200013" <= this value exists in the BD, if I type "20200200014", it prints me the message "This value does not exist in the database", but if I click "Send"(button) it sends, even if the given number does not exist in the BD and fills a table with all blank (null values)
– Lucas
If there is no BD, simply empty the input and disable the button.
– Sam