PHP not displaying results from MySQL database -
i trying display entry mysql database selected data.
if (isset($_get["id"])){ $id=$_get["id"]; $result = getselectedblog($id); while($row = mysqli_fetch_array($result)) { extract($row); ?> <div class="headline"><?php echo $headline ?></div> <div class="subtitle"><?php echo $subtitle ?></div> <div class="content"><?php echo $content ?></div> <?php } here sql statement:
function getselectedblog($id){ $con = mysqli_connect('localhost', 'root', '', 'michaelwebsite') or die('could not connect'); $sql = 'select * tblarticle tblarticle.articleid "$id"'; $result = mysqli_query($con, $sql) or die('entry not exist.:' . mysqli_error($con)); return $result; }
as can see, passing data $id method returns result. nothing being returned. there 3 entries @ moment, if change $id in sql statement either 1, 2 or 3 show corresponding data not work $id variable.
the url end correct info ?id=1.
please excuse me if stupid, have been stuck on hours now!!
all of these answers solve problem, none have mentioned or prevented sql injection.
in case recommend (assuming articleid integer field).
$sql = 'select * tblarticle tblarticle.articleid "' . (int)$id . '"'; i'm curious why using like id field.
note: since using mysqli, i'd encourage @ prepared statements.
Comments
Post a Comment