i dont know whats wrong please help? 4 error message from while loop from assigning db data to arrray
$conn = new mysqli('localhost','root','','project_nlt');
$qry = "select *
from useri_nfo
where skills='$skill'
order by u_id ASC";
if ($row = $conn->query($qry)) {
$numrow = $row->num_rows;
$name = array($numrow);
$profile_img=array($numrow);
$skills = array($numrow);
$address = array($numrow);
$i = 0;
echo $numrow;
while ($r = $row->fetch_array(MYSQLI_ASSOC) && $i < $numrow) {
echo $r;
$name[$i] = $r['user_name'];
$profile_img[$i] = $r['dp'];
$skills[$i] = $r['skills'];
$address[$i] = $r['address'];
echo $name[$i];
$i++;
}
}
In PHP you do not need to initialize arrays. PHP makes array usage extreemly simple
While loops will stop when a false is returned from the fetch, so no limit on rowcount is needed.
So amend the code to
$conn = new mysqli('localhost','root','','project_nlt');
$qry = "select *
from useri_nfo
where skills='$skill'
order by u_id ASC";
if ($row = $conn->query($qry)) {
while ($r = $row->fetch_array(MYSQLI_ASSOC)) {
//echo $r; you cannot echo an array, try `var_dump() or print_r()
$name[] = $r['user_name'];
$profile_img[] = $r['dp'];
$skills[] = $r['skills'];
$address[] = $r['address'];
}
}
Your script is open to SQL Injection Attack. Even if you are escaping inputs, its not safe! You should consider using prepared parameterized statements in either the
MYSQLI_
orPDO
API's instead of concatenated values
So this should really be coded as
$conn = new mysqli('localhost','root','','project_nlt');
$qry = "select *
from useri_nfo
where skills = ?
order by u_id ASC";
$stmt = $conn->prepare($sql);
$stmt->bind_param('s', $skills)
$stmt->execute();
$result = $stmt-<get_reslt();
while ($r = $result->fetch_array(MYSQLI_ASSOC)) {
//echo $r; you cannot echo an array, try `var_dump() or print_r()
$name[] = $r['user_name'];
$profile_img[] = $r['dp'];
$skills[] = $r['skills'];
$address[] = $r['address'];
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments