0
I have a form, where when typing a plate in the registration field, it lists the plates. And each registration is related to a person and their data: name, date of birth, date of admission.
However, I need that when I click on the registration, it fill in the other fields of the form. And that part I’m not getting to elaborate and execute.
This is the code that lists the registrations:
<?php
$host="localhost"; // Host name
$username="teste_inezb"; // Mysql username
$password=""; // Mysql password
$db_name="teste_login"; // Database name
$con = mysql_connect($host,$username,$password) or die(mysql_error());
mysql_select_db($db_name, $con) or die(mysql_error());
$q = strtolower($_GET["q"]);
if (!$q) return;
$sql = "select DISTINCT MATRIC from DBWEBCAD where MATRIC LIKE '%$q%'";
$rsd = mysql_query($sql);
while($rs = mysql_fetch_array($rsd)) {
$cmat = $rs['MATRIC'];
$cname = $rs ['NOMSCODEP'];
echo "$cmat\n", "$cname\n";
}
?>
Do you want to change pages to do this or stay the same ?
– Diego Souza
Anyway. The registration is already listed, I just need it to complete the required fields.
– Inez Boldrin
I’m not quite able to understand what your problem is which difficulties you are facing. You could be more specific?
– gato
I edited the question
– Inez Boldrin
@Inezboldrin you will have to create another function that by clicking on the registration, fill in the fields. This can be done with JS, AJAX.
– Diego Souza
Good afternoon @Inezboldrin, a recommendation outside the scope of your question: As your code stands, it is vulnerable to SQL Injection. So much so that this function
mysql_query
was depreciated by PHP. I suggest using other alternatives such as Mysqli or PDO, and use concepts such asprepare statements
, for example.– mrlew
Regarding your question, I believe you want to make a request to the server after the page loaded, to search for a data that arose from the interaction with the user (in this case, the registration). This? This process in javascript is called AJAX, and involves creating a client-side script in javacript and a PHP script to return this data (in the form of JSON, for example). Anyway, you would have to show us your current HTML/JS implementation to better understand your problem. Hugs.
– mrlew
So, I did some research and saw about Ajax, JSON however, I don’t know how to elaborate a code with them. You have some more explanatory video?
– Inez Boldrin
@Inezboldrin you already know something of
JavaScript
? If not, I recommend learning the basics of this language. Afterwards, you can study jQuery, a well-known library that makes life easier for those who work with js (in general, works on javascript, but makes it easier - especially for those who are starting and do not want to delve into pure javascript -, and more compatible your code - you do not need to write different things for other browsers). Inside jQuery there are methods to get what you want here ($.ajax
).– mrlew
As for classes, I’m not really into it. But I recommend looking on Youtube, there are a lot of good people there.
– mrlew