0

I have tried ready various articles to resolve the issue to no avail. I using a form to post data to my php file. Then I'm trying to find the row that has the matching value. I keep getting these errors: Undefined index: barcode & Trying to get property of non-object Can someone help me resolve this issue?

//barcode is serialized data from a form and equals 'barcode=2147483647'

$barcode = $_GET['barcode'];


$sql = "SELECT id FROM the_DB WHERE barcode = '%$barcode%'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo 'id:' . $row["id"]. '<br>Name: ' . $row["item_name"]. '<br> Barcode ' . $row["barcode"]. '<br><img src="'.$row["image"].'" height="100px">';
    }
} else {
    echo "0 results";
}
Rafael
  • 3,593
  • 3
  • 17
  • 27

2 Answers2

0

change query as follows

 $sql = "SELECT * FROM the_DB WHERE barcode = '%$barcode%'";
Vigikaran
  • 725
  • 1
  • 10
  • 27
0

Following Possibility for this error:

  • Check your variable in scope.
  • If you get request from other page check your request method.
  • If you are use session must start before use.
  • echo and exit to check your variable have value or not.

You are fetching an column that are not in your result set.

    $barcode = $_GET['barcode'];
if(isset($barcode))
{

$sql = "SELECT * FROM the_DB WHERE barcode = '%$barcode%'";
$result = $conn->query($sql);

$rows = array();
while ($row = mysql_fetch_object($result)) {
    $rows[] = $row;

}

}
Vasim Shaikh
  • 4,485
  • 2
  • 23
  • 52