php - Data is not fetched from MySQL database -


i trying fetch data data base, it's not giving me output. it's displaying "all charges". code below:

<?php         include 'precode.php';         include 'header.php';          echo '<body><div class="standardlayout">';         include 'systemmenu.php';         echo '<h4>all charges</h4>';            $user = unserialize($_session['user']);           echo $query = "select * billingitems userid=' " . $user-> userid .  " ' order deliverytimestamp desc";            $result = mysqli_query($db, $query);          while ($row = mysqli_fetch_array($result)) {          echo  $row['type'] . '<br>' .                  'cost: $' . $row['amount'] . '<br>' .                  ' finalized: ' . $row['deliverytimestamp']  ;  }         echo '</div></body></html>';          $_session['user'] = serialize($user);         include 'footer.html'; ?> 

here output echo $query;:

all charges object(user)#2 (11) { ["orders"]=> null ["fname"]=> string(6) "kimmie" ["lname"]=> string(4) "kaur" ["address"]=> string(10) "6768bbnmmn" ["phone"]=> string(11) "66767798898" ["email"]=> string(6) "kimmie" ["userid"]=> string(3) "108" ["password"]=> string(4) "kaur" ["passwordx"]=> null ["amountowed"]=> string(1) "0" ["zip"]=> string(6) "768798" } select * billingitems userid=' 108 ' order deliverytimestamp desc

seems me query building problem, because this

$query = "select * billingitems userid=' " . $user-> userid .  " ' order deliverytimestamp desc"; 

will give if id "bob".

select * billingitems userid=' bob ' order deliverytimestamp desc 

you embedding spaces around id, doesn't match contents of column.

the safer way use prepared statements , bind parameters don't run these kinds of bugs. keep safe sql injection. see question details: how can prevent sql-injection in php?


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -