Hello,
I’m trying to get username with search by inputted string of name or ID value from particular record columns in MySQL database table with ID, name and username. If I search for Leila in name column, I want get username column leila77 or ID 3:
ID | name | username
------------------------
1 | Sally | sally123
2 | Jack | jack120
3 | Leila | leila77
4 | Aaron | aaron800
5 | Sara | sara444
TS:
check() {
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
let options = new RequestOptions({ headers: headers });
let postParams = '&name=' + this.name;
this.http.post("http://site.info/php/check.php", JSON.stringify(postParams), options)
.subscribe(data => {
console.log(data['_body']);
}, error => {
console.log(error);
});
}
For example I can check if value of inputted name exist in database table column in check.php this way:
<?php
require 'connection.php';
$name = $_POST['name'];
$sql = "SELECT * from nameTab where name='$name'";
if (mysqli_query($con, $sql)==1)
{
echo 'Name exist';
}
else
{
echo 'Name does not exist';
}
?>
but to get other columns of same record with this way:
<?php
require 'connection.php';
$name = $_POST['name'];
$sql = "SELECT * from nameTab where name='$name'";
$result = mysqli_query($con, $sql);
while($row = $result->fetch_assoc())
{
echo $row["username"];
}
?>
not sure how to get this value, console does not outputs echo, seems like my .ts front end is not proper, advice would be helpful:
