php - Why is the text ignored by Mysql? -
i have problem php code. problem lies in $_get['id']
. can see, output resultset of user matched user id.
the question is, why same result (resultset of user id 1) when enter 2 different values on url?
url 1:
url2:
shouldn't text (randomtext) taken in consideration, because code seems ignore it.
<?php try { $db = new pdo('mysql:host=127.0.0.1;dbname=ptp', 'root', 'root'); $db->setattribute(pdo::attr_errmode, pdo::errmode_exception); } catch (pdoexception $e) { } $id = $_get['id']; $sql = "select * users id = :id"; echo $id . '<br/>'; $query = $db->prepare($sql); $query->bindparam(':id', $id); $query->execute(); while($r = $query->fetch(pdo::fetch_assoc)) { print_r($r); } ?>
just php, mysql cast string "1random"
int 1
. if id field number, query seen "select * users id = 1"
if there random text after 1
just try in php : var_dump('1dfg' == 1)
return true. it's same in mysql.
however, if try find user id "dfg1"
, nothing returned because string can't casted int.
Comments
Post a Comment