-1

i have facing problem in php code. the error is given below:

mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in directory name

the php code is:

<?php
$edit_record = $_GET['edit'];

$query = "select * from std_reg where student_id='edit_record'";

$run = mysqli_query($conn, $query);

while($row = mysqli_fetch_array($run))
{
$id = $row['Student_id'];
$name = $row['name'];
}
?>

can any one help?

Imran Khan
  • 95
  • 2
  • 2
  • 9

5 Answers5

1

You have to add the result type to mysqli_fetch_array.

See the syntax: mysqli_fetch_array(result,resulttype);

while($row = mysqli_fetch_array($run,MYSQLI_ASSOC))
Jens
  • 67,715
  • 15
  • 98
  • 113
1
  1. $row is not defined anywhere. In while loop you must set $row = mysqli_fetch_array($run).

  2. You are not passing value to query correctly. $ is missing here student_id='edit_record'.

    <?php
    $edit_record = mysqli_real_escape_string($conn, $_GET['edit']);
    
    $query = "SELECT * FROM std_reg WHERE student_id='$edit_record'";
    
    $run = mysqli_query($conn, $query);
    
    
    if($run)
    {
        while($row = mysqli_fetch_array($run))
        {
            $id = $row['Student_id'];
            $name = $row['name'];
        }
    }
    ?>
    
Muhammad Hassaan
  • 7,296
  • 6
  • 30
  • 50
1

Give row name to while loop and add $ to edit_record in query

$edit_record = $_GET['edit'];

$query = "select * from std_reg where student_id='$edit_record'";

$run = mysqli_query($conn, $query);

while($row = mysqli_fetch_array($run))
{
  $id = $row['Student_id'];
  $name = $row['name'];
}
Elyor
  • 5,396
  • 8
  • 48
  • 76
0

You should really use mysqli_fetch_assoc rather than mysqli_fetch_array. It gives you the result you wanted without having to explicitly say what type of array you wanted.

Jason Spicer
  • 249
  • 1
  • 8
-2

From this query:

$query = "select * from std_reg where student_id='edit_record'";    

To this query:

<?php
$edit_record = $_GET['edit'];$query = "select * from std_reg where student_id=".$edit_record; //Please try to observed the concatenation

$run = mysqli_query($conn, $query);

while($row = mysqli_fetch_assoc($run)) {
$id = $row['Student_id'];
$name = $row['name'];
}
?>
aldrin27
  • 3,407
  • 3
  • 29
  • 43