Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to fetch result in Mysqli [Undefined offset ]

This is my simple query and even it is not executing , my $total is 3;

$pnc = array();

$pnc[] = ('318','259','789');

$total = count($pnc);

for($p=0;$p<$total;$p++)
{
   echo $query = "select `id` from `patents` where `number`=?";
   $stmt = $mysqli->prepare($query) or $mysqli->error ;
   $stmt->bind_param("s",$pnc[$p]);
   $stmt->execute();
   $stmt->bind_result($id);
   $stmt->fetch();
   echo $id;
}

When i am echoing query i am getting

select `id` from `patents` where `number`='318'

and when i am running this query in phpmyadmin its getting 'id' value , but here it is unable to get the id,

Is this the problem occurs due to Undefined offsetbind_param("s",$pnc[$p]); even i am getting value of each element of the array.

Please give a solution for this thanks.

like image 930
Afsar Avatar asked Nov 25 '25 17:11

Afsar


1 Answers

Change -

$pnc = array();
$pnc[] = ('318','259','789');
$total = count($pnc);

TO

$pnc = array('318', '259', '789');
echo $total = count($pnc);

Error in your code --> Error

like image 51
swapnesh Avatar answered Nov 27 '25 06:11

swapnesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!