Thomas Smyth Thomas Smyth - 9 months ago 52
SQL Question

PHP / JAVASCRIPT / SQL Failing to show table

I'm trying to create a query system to display all the user accounts within my system to the system admin, so that later I can add a feature to edit them, etc. I've created a PHP file to find the results and create a table, which is then echoed back to the javascript and displayed. However, the system only displays 0 and not the table. I can only assume this means that nothing was found, but my system is meant to have catches for this and I'm 90% sure it should be finding something.


function UserSearch(){
var Search = $("#txtUserSearch" ).val();
var Type = $("#sltQuery" ).val()
$.post('../functions/php/fncusersearch.php', {Search: Search, Type: Type}, function(data) {
if (data == 1){
$('#divSearchResults').html('<p class="text-center text-danger bg-danger" id="pUPInc">No Accounts Matched your Search!</p>');
else if (data == 3){
$('#divSearchResults').html('<p class="text-center text-danger bg-danger" id="pUPInc">Database not found! Please try again later.</p>');



//Retrieves variables from Javascript.
$Search = $_POST["Search"];
$Type = $_POST["Type"];

if ($Type == "Registration Date"){
$Type = "joined";
else if ($Type == "Account Rank"){
$Type = "rank";

include "db/openlogindb.php";
if($DBError == true){
$data = 3;

$UserSearch = "SELECT username, surname, forename, joined, rank FROM users WHERE ".$Type." LIKE '%".$Search."%'";

$results = mysqli_query($conn, $UserSearch);

if(mysqli_num_rows($results) == 0){
$data = 1;
$data = '';
$data += '<table class="table table-striped">';

while($row = mysqli_fetch_assoc($results)){
$data += "<tr><td>".$row['surname']."</td><td>".$row['forename']."</td><td>".$row['username']."</td><td>".$row['joined']."</td><td>".$row['rank']."</td></tr>";

$data += "</table>";

include "db/closelogindb.php";

echo $data;

enter image description here

Answer Source

your using wrong operator for concatenation

$data += '<table class="table table-striped">';

replace + symbol with .


$data .= '<table class="table table-striped">';