I am trying to create a form that will be complemented with data from the database. This is how it works: the customer enters the company number, and the form searches in the database if the number exists, if yes, it replaces value in the input "Company name" and in the input "Company address"
I almost did it, the problem is that the name and address of the company show up, however, as text. I would like them to ``show up in inputs, what am I doing wrong?
I just use the for do this, I don't have any idea how to do it correctly.
<html>
<head>
<meta charset="UTF-8">
<link href="https://fonts.googleapis.com/css?family=Poppins&display=swap" rel="stylesheet">
<link rel="stylesheet" href="lib/jquery-ui.css" />
<script src="lib/jquery-1.8.3.js"></script>
<script src="lib/jquery-ui.js"></script>
<script src="lib/jquery.ui.datepicker-pl.js"></script>
<script type='text/javascript' src='lib/jquery.bgiframe.min.js'></script>
<script type='text/javascript' src='lib/jquery.ajaxQueue.js'></script>
<script type='text/javascript' src='lib/thickbox-compressed.js'></script>
<script type='text/javascript' src='lib/jquery.autocomplete.js'></script>
<link rel="stylesheet" type="text/css" href="lib/jquery.autocomplete.css" />
<link rel="stylesheet" type="text/css" href="lib/lib/thickbox.css" />
<script>onload="window.parent.parent.scrollTo(0,0)"</script>
//There's the script to show date from database
<script>
function showHint(str) {
if (str.length == 0) {
document.getElementById("KonNaz").innerHTML = "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("KonNaz").innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "gethint.php?q=" + str, true);
xmlhttp.send();
}
{
if (str.length == 0) {
document.getElementById("KonAdr").innerHTML = "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("KonAdr").innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "gethint2.php?q=" + str, true);
xmlhttp.send();
}
}
}
</script>
</head>
<body>
//Theres a form
<form action="baza_danych_faktury.php" method="post" enctype="multipart/form-data" class="form-inline">
Kontrahent NIP (Company Number)</br>
<form>
<div id="KonNaz"><input type="text" placeholder="np. 7740001454" name="KonNip" class="inputspecial" required onkeyup="showHint(this.value)"> </div> </br>
</form>
Kontrahent nazwa (Company Name)</br>
<input type="text" placeholder="np. Polski Koncern Naftowy Orlen" name="KonNaz" id="KonNaz" class="inputspecial" required> </div> </br>
Kontrahent adres (Company Addres)</br>
<div id="KonAdr"><input type="text" placeholder="np. Katowice 40-847 UL. BOCHEŃSKIEGO 99" name="KonAdr" class="inputspecial" required> </div> </br>
(...)
</form>
in gethint.php:
<?php
$q = $_REQUEST["q"];
$dbhost = 'localhost';
$dblogin = 'login';
$dbpass = 'password';
$dbbase = 'database_name';
mysql_connect($dbhost,$dblogin,$dbpass);
mysql_select_db($dbbase) or die("Błąd przy wyborze bazy danych");
mysql_query("SET CHARACTER SET UTF8");
$wynik = mysql_query("SELECT * FROM evdb_nip WHERE NIP = '$q' ")
or die('Błąd zapytania');
if(mysql_num_rows($wynik) > 0) {
while($r = mysql_fetch_assoc($wynik)) {
echo $r[Nazwa_Kontrahenta];
}
}
?>