0

I am trying to fetch my data from database using prepare statement in php and I don't understand what I'm doing wrong in this?

Here is my code :

<?php
$host="localhost";
$user="root";
$password="";
$db="simpleinvoicephp";

$conn=mysqli_connect($host,$user,$password,$db);



$sql="SELECT * FROM invoice_user";

$result=mysqli_prepare($conn,$sql);

mysqli_stmt_bind_param($result,$id);

mysqli_stmt_execute($result);

mysqli_stmt_fetch($result);

echo $id;


?>

Error:

This page isn’t workinglocalhost is currently unable to handle this request.
HTTP ERROR 500

Anyone help me out with this problem?

Thak you

  • `mysqli_stmt_bind_param` is to bind variables to parameters in the SQL, you probably wanted `mysqli_stmt_bind_result`. – Nigel Ren Mar 22 '22 at 07:04
  • @NigelRen yeah I tried this too but isn't work. – Shiva5harma Mar 22 '22 at 07:06
  • If you are trying to bind the parameter as a query criteria, your query will need `WHERE id = ?`. Please clarify: _do you want to fetch all users and bind the result_, or _select a user by `id` column_? – Markus AO Mar 22 '22 at 07:22
  • I would recommend you to [read the manual](https://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php) about mysqli and prepared statements. It contains plenty of different examples. You should also check the web servers error log to get the more specific error message when you're debugging. – M. Eriksson Mar 22 '22 at 07:31

0 Answers0