php - Read value from database, echo -
very basic rookie struggling. echo doesnt show value, text. doing wrong?
connect.php:
<?php $connection = mysqli_connect('test.com.mysql', 'test_com_systems', 'systems'); if (!$connection){ die("database connection failed" . mysqli_error($connection)); } $select_db = mysqli_select_db($connection, 'swaut_com_systems'); if (!$select_db){ die("database selection failed" . mysqli_error($connection)); } ?>
get.php:
<?php require('connect.php'); $query2 = "select systemid user username=test"; $result2 = mysqli_query($connection, $query2); echo ( 'systemid: '.$result2); ?>
assuming have connected database query incorrect. must wrap text values in quotes this
<?php require('connect.php'); $query2 = "select systemid user username='test'"; $result2 = mysqli_query($connection, $query2);
now mysqli_query
submits query database run , result set built. see result set need read result set database using 1 of fetch
functions example
$row = mysqli_fetch_assoc($result2); echo 'systemid: ' . $row['systemid'];
if there more 1 rows in result set must in loop this
while ($row = mysqli_fetch_assoc($result2)){ echo 'systemid: ' . $row['systemid']; }
Comments
Post a Comment